回到顶部的功能

 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>

 

posted @ 2016-07-19 11:38  程序猿凯  阅读(193)  评论(0编辑  收藏  举报