I have this code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script>
window.addEventListener('DOMMouseScroll', mouseWheelEvent);
window.addEventListener('mousewheel', mouseWheelEvent);
function mouseWheelEvent() {
alert(1);
}
</script>
</body>
</html>
It works in Chrome & Firefox. However, it doesn't work with my laptop dell xps 13 9434's touchpad in IE & edge. But it does work with (some) other laptops' touchpads. What to do? jQuery is no problem.
"what doesn't work?" => There is no alert in scroll when using 2 fingers like you use to scroll in browsers.
The obsolete and non-standard mousewheel event is fired asynchronously at an Element to provide updates while a mouse wheel or similar device is operated.
About Mousewheel JS Mousewheel is a jQuery plugin that adds cross-browser mouse wheel support. Also, Scroll distance can be measured using Delta normalization.
The scroll wheel that is located in the middle of the mouse is used to scroll up and down on any page without using the vertical scroll bar on the right hand side of a document or webpage. The scroll wheel can also be used as a third button on the mouse.
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);
function mouseWheelEvent() {
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With