The events of the Pulley scrolling page are encountered in the web effects, but they are implemented differently in different browsers. The following methods I implemented are compatible with common browsers.
function GetData (event) {
var e = Event | | window.event;
Gets the scrolling distance (FF each scrolling data is 3 or-3, others are 120 or -120)
var data = E.detail | | e.wheeldelta;
alert (data);
}
Binding event methods other than IE
if (document.addeventlistener &&!document.attachevent)
{
Document.addeventlistener (' MouseWheel ', getData);
FF bound scrolling Event
document.addeventlistener (' Dommousescroll ', getData);
}
IE
Else if (document.attachevent &&!document.addeventlistener) {
document.attachevent (' OnMouseWheel ', getData);
} else{
window.onmousewheel = getData;
}
Notable in your code:
1 Why use Document.addeventlistener &&!document.attachevent to differentiate IE?
Attachevent and DetachEvent are the Internet-specific binding event and bind event methods that exist only in IE. However, there is a more general AddEventListener method to bind events in ie9+ browsers. There is a Document.addeventlistener method in the browser that excludes the IE8 and its version, but includes the Ie9+ browser, so &&!document.attachevent is used later to exclude the Ie9+ browser.
2 It is noteworthy that there is no MouseWheel event in the FF browser, and the time to trigger scrolling is dommousescroll.
3 It is also noteworthy that when you use the AddEventListener binding event, the event name is not preceded on, and you need to add on when using the Attachevent binding event in IE.