jQuery中是否有垂直滚动事件 [英] Is there a vertical scroll event in jQuery

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

问题描述

我有一个与scroll()事件绑定的函数,但事实是我希望仅在垂直滚动(我也有一些水平滚动)的情况下才触发该函数.

I have a function that I bound with scroll() event, but the fact is I want the function to be triggered only in case of vertical scroll ( I have some horizontal scroll too).

我在jQuery文档中没有看到这种可能性,这样做有技巧吗?

I didn't see such possibility in the documentation of jQuery, might there be a trick to do so?

推荐答案

没有特定事件,但是您可以测试.scrollLeft()位置以查看它是否已从先前存储的位置移出.

There isn't a specific event, but you could test the .scrollLeft() position to see if it has moved from a previously stored position.

类似这样的东西:

var prevLeft = 0;
$(document).scroll( function(evt) {
    var currentLeft = $(this).scrollLeft();
    if(prevLeft != currentLeft) {
        prevLeft = currentLeft;
        console.log("I scrolled horizontally.");
    }
});

  • http://api.jquery.com/scrollLeft/
    • http://api.jquery.com/scrollLeft/
    • 这篇关于jQuery中是否有垂直滚动事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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