我有一个与 scroll()
事件绑定(bind)的函数,但事实是我希望仅在垂直滚动的情况下触发该函数(我也有一些水平滚动)。
我在 jQuery 的文档中没有看到这种可能性,是否有一个技巧可以做到这一点?
最佳答案
没有特定事件,但您可以测试 .scrollLeft()
位置以查看它是否已从之前存储的位置移动。
类似这样的事情:
var prevLeft = 0;
$(document).scroll( function(evt) {
var currentLeft = $(this).scrollLeft();
if(prevLeft != currentLeft) {
prevLeft = currentLeft;
console.log("I scrolled horizontally.");
}
});
关于jquery - jQuery中有垂直滚动事件吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3186622/