在js中获取水平滚动事件 [英] get horizontal scroll event in js
本文介绍了在js中获取水平滚动事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要做的是在用户水平滚动div时捕获事件。
对于垂直滚动我使用事件'mousewheel'并且它正常工作。 (水平滚动是通过触摸板上的两个手指拖动来执行的 - 我在Mac OS上进行测试)。
感谢您的回复
What I want to do, is to catch the event when the user is scrolling div horizontally. For vertical scroll I am using event 'mousewheel' and it's working properly. ( horizontal scroll is performed by a two finger drag on the touchpad - I am testing on Mac OS). Thank you for any response
推荐答案
您可以通过以下方式处理水平滚动:
You can handle horizontal scrolling by :
$("#someContainer").on("scroll", function (e) {
horizontal = e.currentTarget.scrollLeft;
vertical = e.currentTarget.scrollTop;
});
在这种情况下,这个绑定此元素上的所有类型的滚动事件,这样你也可以处理
In this case this bind all kind of scroll events on this element so you can also handle
垂直按 e.currentTarget.scrollTop
和
水平按 e.currentTarget.scrollLeft
这篇关于在js中获取水平滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文