回到顶部

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  2. <html xmlns="http://www.w3.org/1999/xhtml">   
  3. <head>   
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
  5. <title>仿淘宝回到顶部代码</title>   
  6. <!--[if lt IE 7]>   
  7. <style type="text/css">  
  8. #gotopbtn{position:absolute;top:expression(eval(document.documentElement.scrollTop + 350));}   
  9. </style>   
  10. <![endif]-->   
  11. <style type="text/css">   
  12. body{   
  13. font:12px Verdana, Geneva, sans-serif;   
  14. line-height:1.2;   
  15. text-align:center;   
  16. margin:0px;   
  17. }  
  18. #gotopbtn {   
  19. width:100px;   
  20. height:30px;   
  21. background:#fff;   
  22. position:fixed;   
  23. bottom:100px;   
  24. right:20px;   
  25. display:none;   
  26. cursor:pointer;   
  27. font-size:14px;   
  28. line-height:30px;   
  29. border:1px solid #aaa;   
  30. }   
  31. .main{   
  32. width:100%;   
  33. background:#ccc;   
  34. margin:0 auto;   
  35. }   
  36. </style>   
  37. </head>   
  38. <body>   
  39. <div class="main">   
  40. <img src="/webkey.png" width="1004" height="2408"><br>   
  41. </div>   
  42. <div id="gotopbtn">返回顶部</div>   
  43. <script type="text/javascript">   
  44. backTop=function (btnId){   
  45. var btn=document.getElementById(btnId);   
  46. var d=document.documentElement;   
  47. window.οnscrοll=set;   
  48. btn.οnclick=function (){   
  49. btn.style.display="none";   
  50. window.οnscrοll=null;   
  51. this.timer=setInterval(function(){   
  52. d.scrollTop-=Math.ceil(d.scrollTop*0.1);   
  53. if(d.scrollTop==0) clearInterval(btn.timer,window.οnscrοll=set);   
  54. },10);   
  55. };   
  56. function set(){btn.style.display=d.scrollTop?'block':"none"}   
  57. };   
  58. backTop('gotopbtn');   
  59. </script>   
  60. </body>   
  61. </html>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值