返回顶部的过渡式写法

 利用了 requestAnimationFrame() 与 cancelAnimationFrame() 的函数,及 函数 递归的写法 

hometop.onclick=function(){
// window.scroll(0,0);
cancelAnimationFrame(timer);
var timer = requestAnimationFrame(function fn(){
var oTop = document.body.scrollTop || document.documentElement.scrollTop;
if(oTop > 0){
scrollTo(0,oTop-50);
timer = requestAnimationFrame(fn);
}else{
cancelAnimationFrame(timer);
}
});
}
原文地址:https://www.cnblogs.com/shangjun6/p/11278921.html