Mousewheel & Dommousescroll Event In Ie & Edge
Solution 1:
Edit
After some research it seems that the problem is actually Microsoft's.
There is an open issue about it in EdgeHTML issue tracker for almost one year already.
Basically it says that wheel events do not work in Edge (And older IE versions) when using Precision Touchpads.
By the way I dont delete the rest of the answer as it is still relevant. You should use wheel
instead anyway.
You should listen to wheel
:
window.addEventListener('wheel', mouseWheelEvent);
It has replaced both mousewheel
and DOMMouseScroll
which are deprecated by now and is supported by all browsers.
Cross browser example:
window.addEventListener('wheel', mouseWheelEvent);
functionmouseWheelEvent() {
console.log("Fired");
}
<h1>
Hodor!
</h1><h1>
Hodor!
</h1><h1>
Hodor!
</h1><h1>
Hodor!
</h1><h1>
Hodor!
</h1><h1>
Hodor!
</h1><h1>
Hodor!
</h1>
And JSFiddle demo
Solution 2:
Staring EdgeHTML 17, Microsoft supports Pointer Events to solve the issue.
As of today, pointer events are supported by all major browsers except Safari:
Solution 3:
Some older IE version doesn't support addEventListener, they support attachEvent instead.
Try a crossBrowser addEventListener:
if ( window.attachEvent ) {
window.attachEvent('on'+eventType, yourHandler); // in your case "scroll"
} else {
window.addEventListener ...
}
Pay attention to the page height: it won't work if there is no offset. If there is no offset in your page, then use this:
document.attachEvent('onmousewheel', mouseWheelEvent); // the event is attached to document
Post a Comment for "Mousewheel & Dommousescroll Event In Ie & Edge"