chrome 调度轮事件

发布于 2024-11-25 10:17:28 字数 680 浏览 2 评论 0 原文

我正在尝试在 chrome 中发送轮子事件,但仍然无法成功。我正在使用 WheelEvent 对象,但似乎无法正确“初始化”它。无论我做什么,增量始终为 0。我查看了 规范,但没有帮助。更有趣的是,当我实际用鼠标滚轮滚动并尝试调度该事件时,我捕获了该事件,但增量再次为 0。有人遇到过这样的问题吗?这可能是一个错误吗?任何帮助都会很棒!

//dispatching the wheel event
var evt = document.createEvent("WheelEvent");
evt.initEvent("mousewheel", true, true, null, 0, 0, 0, 0, 0, false, false, false, false, 0, null, -120);
window.dispatchEvent(evt)

// catching the wheel event
window.addEventListener('mousewheel', callback, true);
callback = function(evt){
       console.log(evt)
}

I'm trying to dispatch a wheel event in chrome but still can't make it. I am using the WheelEvent object but seems that just cannot "init" it right. Whatever I do, delta is always 0. I looked at the specification, but no help. More interesting, I captured the event when I actually scroll with mouse wheel and tried to dispatch that event, but again the deltas were 0. Did anyone encountered such problem? Is this maybe a bug? Any help would be great!

//dispatching the wheel event
var evt = document.createEvent("WheelEvent");
evt.initEvent("mousewheel", true, true, null, 0, 0, 0, 0, 0, false, false, false, false, 0, null, -120);
window.dispatchEvent(evt)

// catching the wheel event
window.addEventListener('mousewheel', callback, true);
callback = function(evt){
       console.log(evt)
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只有一腔孤勇 2024-12-02 10:17:28

起初我不再需要这个功能,但最近我又回到了这个问题,并找到了一种在 Chrome 上正确调度轮子事件的方法。抱歉耽搁了,我完全忘记了这个问题。代码如下:

var evt = document.createEvent("WheelEvent");
evt.initWebKitWheelEvent(deltaX, deltaY, window, screenX, screenY, clientX,
                        clientY, ctrlKey, altKey, shiftKey, metaKey);
node.dispatchEvent(evt);

更多信息可以在这里找到。
希望这有帮助。

At first I didn't need anymore this functionality but I recently got back to this issue and found a way to dispatch wheel event properly on Chrome. Sorry for the delay, I totally forgot about this issue. The code is as follows:

var evt = document.createEvent("WheelEvent");
evt.initWebKitWheelEvent(deltaX, deltaY, window, screenX, screenY, clientX,
                        clientY, ctrlKey, altKey, shiftKey, metaKey);
node.dispatchEvent(evt);

More information can be found here.
Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文