div跟随页面滚动

时间:2023-03-09 21:49:43
div跟随页面滚动
$(document).ready(function(){
var timer;
$(window).scroll(function (){
clearInterval(timer);
var topScroll=getScroll();
var topDiv="100px";
var top=topScroll+parseInt(topDiv);
timer=setInterval(function(){
//$(".test").css("top", top+"px");
$("#splitsuspend_div").stop(true).animate({"top":top},50);
},50)
})
})
function getScroll(){
var bodyTop = 0;
if (typeof window.pageYOffset != 'undefined') {
bodyTop = window.pageYOffset;
} else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
bodyTop = document.documentElement.scrollTop;
}
else if (typeof document.body != 'undefined') {
bodyTop = document.body.scrollTop;
}
return bodyTop
}