javascript jQuery - 检测水平滚动位置(像素),然后执行函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16781296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery - Detect Horizontal Scroll Position (pixels), then do function
提问by tehSUPERADMIN
I have a jQuery function that I would like to have occur when the user reaches 25px
while horizontally scrolling on the page (i.e. html, body
). Horizontal scroll = x-axis.
我有一个 jQuery 函数,我希望在用户25px
在页面上水平滚动时到达它(即html, body
)。水平滚动 = x 轴。
In other words, I would like jQuery to detect when the user reaches 25px on the x-axis and then execute my function.
换句话说,我希望 jQuery 检测用户何时在 x 轴上达到 25px,然后执行我的函数。
How could this be accomplished? Have been looking and trying different functions for an hour with no luck. Thanks to all in advance.
这怎么可能实现?一个小时以来一直在寻找和尝试不同的功能,但没有运气。提前感谢大家。
回答by Nile
Example: http://jsfiddle.net/vm28X/1/
示例:http: //jsfiddle.net/vm28X/1/
$(document).scroll(function(){
if($(this).scrollLeft() >= 25){
yourFunction();
}
});
function yourFunction(){
//I scrolled over 25
}
回答by thmshd
I'd like to point you to this answer, you only have to replace scrollTop(...)
with scrollLeft(...)
for the x-axis.
我想你点这个答案,你只需要更换scrollTop(...)
同scrollLeft(...)
为x轴。