html部分

<div id="ease-target"><span id="ease\_go\_top"><i class="fa fa-chevron-up"></i></span>
</div>

js部分

// 返回顶部
var ease\_go\_top = document.getElementById("ease\_go\_top");
 function ease_scrollToTop(t){
 var x = 0;
 var scroll_Top = document.body.scrollTop || document.documentElement.scrollTop;
 var time = setInterval(function(){
 x+=scroll_Top*30/t;
 if(x>scroll_Top){
 clearInterval(time);
 document.body.scrollTop = 0;
 document.documentElement.scrollTop = 0;
 }else{
 document.body.scrollTop = scroll_Top-x;
 document.documentElement.scrollTop = scroll_Top-x;
 }
 },30)
 }
 ease\_go\_top.onclick = function(){
 ease_scrollToTop(1000);
 }
// end-返回顶部

添加css样式

#ease\_go\_top{
 position: fixed;
 right: 10px;
 bottom: 10px;
 width: 50px;
 height: 50px;
 text-align: center;
 background: rgba(255,255,255,0.6);
 font-size: 30px;
 cursor: pointer;
 
}
#ease\_go\_top i{
 font-size: 30px;
}
最后修改:2019 年 12 月 10 日 07 : 43 PM
如果觉得我的文章对你有用,请随意赞赏