A simple example of scrolling event bindings for JS Mouse pulleys

Source: Internet
Author: User

  This article mainly introduces a simple example of a JS mouse pulley scrolling Event binding (compatible with mainstream browsers). Need friends can come to the reference, I hope to help you.

  Code as follows:/** event handler for mouse wheel event.           * Mouse scrolling event            */          var wheel = function (event) {              var delta = 0;               if (!event) * for IE. *                   event = window.event;               if (Event.wheeldelta) {/* ie/opera. */        &NBSP ;         delta = event.wheeldelta/120;              } else if (event.detail) {            &NBS P    /** Mozilla case. *            ,      /** in Mozilla, sign of Delta are different than in IE.&N Bsp                  * Also, Delta is multiple of 3.                   */                & nbsp Delta =-EVENT.DETAIL/3;              /**               If Delta is Nonzer O, handle it.               * Basically, Delta is now positive if wheel was scroll Ed up,               * and negative, if wheel was scrolled down.    &NBS P          */              if (Delta)       &NBS P           handle (delta);              /** prevent default actions caused by mouse wheel.      &N Bsp        * that might to ugly, but we handle scrolls somehow            &N Bsp  * anyway, so don ' t bother here.               */              if (Event.preventdefau LT)                   Event.preventdefault ();               Event.returnvalue = false;           {           /** initialization code.            * If your own event management code, change it as required.           */          if (Window.addeventlistener) {      &NBSP ;      /** Dommousescroll is for Mozilla. *               Window.addeventlistener (' Dommousescroll ', wheel, false);           {         /** Ie/opera. *           Window.onmousewheel = Document.onmousewheel = wheel;            /** this are high-level function.           * It must react to Delta Bei Ng more/less than zero.           */          var handle = Functio N (Delta) {              var random_num = Math.floor (Math.random () * +); &nbsp ;             if (Delta < 0) {                &NBS P Alert ("Mouse pulley scrolling down: + Delta +" Times!) "); 1                   $ ("Btn_next_pic"). OnClick (Random_num);                   return;              } else {                 / /alert ("Mouse pulley scrolling up:" + Delta + "Times!") "); -1                   $ ("Btn_last_pic"). OnClick (Random_num);       &nbsp           return;               {         }    

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.