只是一个小代码,还没有测试过,但我希望它接近你想要的,使用
offset()
在滚动页面时检索顶部位置。。
并设置
xtop
变量,然后调用
doAnimation()
每次页面滚动时,请记住调用
stop()
方法,以便动画缓存不会提示系统的速度。
var xtop;
window.onScroll = function(){
xtop = $(window).offset().top; //get the top position.
doAnimation();
}
function doAnimation(){
$(".test2").stop().animate({top: xtop}, 10000, "linear");
}
xtop公司
位置在10秒(10000毫秒),我希望它能工作。