Luk*_*kas 15 javascript jquery scroll
我的脚本有些问题.所以,我想检测滚动操作的结束.当我滚动时,我有警报,但如果我结束它,则不会.你能帮助我吗?这是我的代码:
var animatable = $('body, html');
var animating = false;
animatable.animate( {scrollTop: $('#foo').offset()})
$(window).scroll(function(e) {
if(!animating){
animatable.stop(false, true);
alert('stop scrolling');
}
animating = false;
});?
Run Code Online (Sandbox Code Playgroud)
和一些小提琴:http://jsfiddle.net/yhnKR/
And*_*ndy 16
这是你想要实现的目标:
$('body').animate( {scrollTop: $('#foo').offset().top},1000,function(){
alert('stop scrolling');
});
Run Code Online (Sandbox Code Playgroud)
如果使用jquery为滚动设置动画,则不必观看滚动事件.
好的,如果要检测用户何时停止滚动,则必须使用超时来检查用户是否已停止.否则,您将获得每个滚动步骤的事件.像这样:
var delay = 1000;
var timeout = null;
$(window).bind('scroll',function(){
clearTimeout(timeout);
timeout = setTimeout(function(){
alert('scrolling stopped');
},delay);
});??????????
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26318 次 |
| 最近记录: |