回到顶部的功能

 1     <a class="totop" id="to_top"></a>
 2 
 3 <script>
 4 /*回到顶部的功能*/
 5 window.onload = function(){
 6   var oTop = document.getElementById("to_top");
 7   var screenh = document.documentElement.clientHeight || document.body.clientHeight;
 8   oTop.style.top = screenh - oTop.offsetHeight + "px";
 9   window.onscroll = function(){
10     var scrolltop = document.documentElement.scrollTop || document.body.scrollTop;
11     oTop.style.top = screenh - oTop.offsetHeight + scrolltop +"px";
12   }
13   oTop.onclick = function(){
14     document.documentElement.scrollTop = document.body.scrollTop =0;
15   }
16 }  
17 </script>
原文地址:https://www.cnblogs.com/clear93/p/5684133.html