function scroll(obj/*要滚动到的位置的元素*/){
var scrollHeight = obj.offsetTop;
clearInterval(obj.timer);
obj.timer = setInterval(function(){
var bodyScroll = document.documentElement.scrollTop || document.body.scrollTop;
if(bodyScroll == scrollHeight ) clearInterval(obj.timer);
var iSpeed = (scrollHeight - bodyScroll) / 5;
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
bodyScroll += iSpeed;
document.body.scrollTop = bodyScroll;
document.documentElement.scrollTop = bodyScroll;
},50);
}
时间: 2024-11-25 13:14:57