如何使用jQuery检测水平滚动?
这将获得所有卷轴:
$(window).scroll(function () {
alert('in');
});
Run Code Online (Sandbox Code Playgroud)
我只想要横向的.
ale*_*lex 41
这似乎有效.
var lastScrollLeft = 0;
$(window).scroll(function() {
var documentScrollLeft = $(document).scrollLeft();
if (lastScrollLeft != documentScrollLeft) {
console.log('scroll x');
lastScrollLeft = documentScrollLeft;
}
});
Run Code Online (Sandbox Code Playgroud)
基于以上代码在水平滚动中显示左或右方向的更新:
var lastPos = 0;
$(window).scroll(function() {
var currPos = $(document).scrollLeft();
if (lastPos < currPos) {
console.log('scroll right');
}
if (lastPos > currPos)
{
console.log('scroll left');
}
lastPos = currPos;
});
Run Code Online (Sandbox Code Playgroud)
在http://jsfiddle.net/EsPk7/7/进行测试
| 归档时间: |
|
| 查看次数: |
55911 次 |
| 最近记录: |