2012-04-10 38 views

回答

2

您可以使用滚动处理程序更新标签。

$(document).scroll(function(){ 
    $("#scrollHeight").html($(document).scrollTop()); 
}); 

http://jsfiddle.net/A2s9Q/7/

+0

你能解释为什么你选择在$(函数)内封装init滚动函数和新函数吗?另外,谢谢你,你的解决方案非常好用 – 2012-04-11 03:37:40

+0

jQuery ready()或等价的$()只是等待文档加载来绑定任何处理程序,以确保脚本的时间恰好在恰当的时刻发生。从技术上讲,on()处理程序在文档准备就绪时不需要被调用,因为它的运行方式可能已经过时了。阅读更多关于ready()的信息:http://api.jquery.com/ready/和on()在这里:http://api.jquery.com/on/ – r0m4n 2012-04-11 05:28:01

1

使用setTimeout

(function updateScrollheight(){ 
    if(animating){ 
     $('#scrollHeight').html($(document).scrollTop()); 
     setTimeout(updateScrollheight, 200); 
    } 
})(); 

这里是DEMO

1

你可以使用从.animate步骤选项(属性,选项)其中tihs进入选项数组以及您的其他选项

step: function(now, fx){$('#scrollHeight').html(now)}