码迷,mamicode.com
首页 > 其他好文 > 详细

回到顶部的功能

时间:2016-07-19 13:36:18      阅读:81      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!