首页 > 其他 > 详细

回到顶部的功能

时间:2016-07-19 13:33:04      阅读:153      评论:0      收藏:0      [点我收藏+]
 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>

 

回到顶部的功能

原文:http://www.cnblogs.com/clear93/p/5684133.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!