[英]jQuery - How to detect scrollLeft AND scrollTop
I have the following jQuery code that currently detects if the user scrolls horizontally ( scrollLeft
) past 500px
then fires the included function. 我有以下jQuery代码,当前检测用户是否水平滚动(
scrollLeft
)超过500px
然后触发包含的函数。
jQuery(document).on('scroll', function() {
if(jQuery(this).scrollLeft() >= 500) {
mysuperduperfunction();
}});
I'd now like for the function to also detect if the user scrolls vertically ( scrollTop
) past 500px
and fire the same function. 我现在想要该功能还可以检测用户是否垂直滚动(
scrollTop
)超过500px
并500px
相同的功能。
In other words, if the user either scrolls left 500px
or scrolls down 500px
, I need jQuery to detect this. 换句话说,如果用户要么向左滚动
500px
或向下滚动500px
,我需要jQuery来检测这一点。
Can this be accomplished? 这可以实现吗? How?
怎么样? Thanks!
谢谢!
use || 使用||
jQuery(document).on('scroll', function() {
that = jQuery(this);
if(that.scrollLeft() >= 500 || that.scrollTop() >= 500) {
mysuperduperfunction();
}});
If this is what you meant I strongly suggest starting here: Eloquent javascript 如果这是你的意思我强烈建议从这里开始: 雄辩的javascript
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.