JS Mouse pulley Rolling Event binding simple example (compatible with mainstream browser) _javascript tips

Source: Internet
Author: User
Copy Code 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. */
Delta = event.wheeldelta/120;
else if (event.detail) {
/** Mozilla case. */
/** in Mozilla, sign of Delta are different than in IE.
* Also, Delta is multiple of 3.
*/
Delta =-EVENT.DETAIL/3;
}
/** If Delta is nonzero, handle it.
* Basically, Delta is now positive if wheel be scrolled up,
* and negative, if wheel is scrolled down.
*/
if (Delta)
Handle (delta);
/** prevent default actions caused by mouse wheel.
* That might is ugly, but we handle scrolls somehow
* Anyway, so don ' t bother here.
*/
if (Event.preventdefault)
Event.preventdefault ();
Event.returnvalue = false;
}

/** initialization code.
* If You use the Your own event management code, change it as required.
*/
if (Window.addeventlistener) {
/** Dommousescroll is for Mozilla. */
Window.addeventlistener (' Dommousescroll ', wheel, false);
}
/** Ie/opera. */
Window.onmousewheel = Document.onmousewheel = wheel;

/** this is high-level function.
* It must react to Delta being more/less than zero.
*/
var handle = function (Delta) {
var random_num = Math.floor (Math.random () * 100) + 50);
if (Delta < 0) {
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);
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.