区分在jquery中向上/向下滚动? [英] Differentiate between scroll up/down in jquery?

查看:109
本文介绍了区分在jquery中向上/向下滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一些很棒的方法来检查使用jquery的滚动条,但是我想知道您是否可以区分用户是否向上或向下滚动?

I have found some great ways to check for where the scroll bar is using jquery, but I was wondering if you can differentiate whether or not the user scrolled up or down?

推荐答案

检查最后一个状态.像这样:

Check for the last state. Something like this:

保留一个变量,例如last_scroll_position,滚动显示时,如果last_scroll_position - current_position > 0,则用户向上滚动,如果小于0,则向下滚动.

Keep a variable, say, last_scroll_position, and when you have a scroll, if last_scroll_position - current_position > 0, the user scrolled up, and down if it's less than 0.

这篇关于区分在jquery中向上/向下滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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