鼠标滚轮& IE浏览器中的dommousescroll事件边缘 [英] Mousewheel & dommousescroll event in IE & Edge
问题描述
我有这段代码:
<!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>
适用于Chrome& Firefox浏览器。但是,它不能与我的笔记本电脑dell xps 13 9434的触控板在IE&边缘。但它确实适用于(某些)其他笔记本电脑的触摸板。该怎么办? jQuery没问题。
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.
什么不起作用? =>使用2个手指时,滚动中没有警报,就像您在浏览器中滚动一样。
"what doesn't work?" => There is no alert in scroll when using 2 fingers like you use to scroll in browsers.
推荐答案
编辑
之后研究似乎问题实际上是微软的问题。
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.
基本上它表示当使用滚轮事件在Edge (和旧的IE版本)中不起作用手势> 精确触摸屏 。
Basically it says that wheel events do not work in Edge (And older IE versions) when using Precision Touchpads.
顺便说一下,我不删除其余的答案,因为它仍然相关。无论如何你应该使用 wheel
。
By the way I dont delete the rest of the answer as it is still relevant. You should use wheel
instead anyway.
你应该听 wheel
:
window.addEventListener('wheel', mouseWheelEvent);
它已经替换了 mousewheel
和 DOMMouseScroll
现在已弃用且。
It has replaced both mousewheel
and DOMMouseScroll
which are deprecated by now and is supported by all browsers.
跨浏览器示例:
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>
这篇关于鼠标滚轮& IE浏览器中的dommousescroll事件边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!