捕捉滚轮事件 [英] Capturing Scroll Wheel Events

查看:109
本文介绍了捕捉滚轮事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在用户在页面不滚动/不可滚动的情况下滚动滚轮时捕获事件。但是,标准JS滚动事件仅在浏览器实际滚动时触发,并且不会针对被设置为隐藏溢出的DOM元素触发。

I want to capture an event when a user scrolls their scroll wheel in a situation where the page does not scroll/is not scrollable. However, the standard JS scroll event only fires when the browser actually does scroll, and will not fire for a DOM element styled to have overflow hidden.

Google maps'滚动到zoom是我正在寻找的行为类型的一个例子。

Google maps' scroll to zoom is an example of the type of behavior I'm looking for.

有没有人知道如何完成这样的事情?

Does anyone have any idea how to accomplish something like this?

谢谢。

推荐答案

你可以很好地捕捉鼠标滚轮事件:

You can capture the mouse-wheel event just fine:

$( '#yourElement' ).on( 'DOMMouseScroll mousewheel', function () {
    ...
});

现场演示: http://jsfiddle.net/chtNP/1/

(我正在使用jQuery绑定事件处理程序,但无论你使用哪种API,它都可以工作。)

(I'm using jQuery to bind the event handler, but it works regardless of which API you use, of course.)

这篇关于捕捉滚轮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆