JavaScript返回顶部

 1 01.01.<head runat="server">    
 2 02.02.    <title></title>    
 3 03.03.   <style type="text/css">    
 4 04.04.#gotopbtn{position:absolute;top:expression(eval(document.documentElement.scrollTop + 350));}     
 5 05.05.</style>    
 6 06.06.<![endif]-->    
 7 07.07.<style type="text/css">    
 8 08.08.body{    
 9 09.09. font:12px Verdana, Geneva, sans-serif;    
10 10.10. line-height:1.2;    
11 11.11. text-align:center;    
12 12.12.}    
13 13.13.#gotopbtn {     
14 14.14. width:20px;    
15 15.15. height:100px;    
16 16.16. background:#fff;    
17 17.17. position:fixed;    
18 18.18. bottom:100px;    
19 19.19. right:330px;    
20 20.20.display:none;    
21 21.21. cursor:pointer;    
22 22.22. font-size:14px;    
23 23.23. line-height:30px;    
24 24.24.}    
25 25.25..main{    
26 26.26. width:50%;    
27 27.27. height:1500px;    
28 28.28. background-color:Green;    
29 29.29. margin:0 auto;    
30 30.30.}    
31 31.31.</style>    
32 32.32.</head>    
33 33.33.<body>    
34 34.34.<div class="main"></div>    
35 35.35.<div id="gotopbtn">返回顶部</div>    
36 36.36.<script type="text/javascript">    
37 37.37.    idTest = document.getElementById('gotopbtn');    
38 38.38.    idTest.onclick = function () {    
39 39.39.        document.documentElement.scrollTop = 0;    
40 40.40.        sb();    
41 41.41.    }    
42 42.42.    window.onscroll = sb;    
43 43.43.    function sb() {    
44 44.44.        if (document.documentElement.scrollTop == 0) {    
45 45.45.            idTest.style.display = "none";    
46 46.46.        } else {    
47 47.47.            idTest.style.display = "block";    
48 48.48.        }    
49 49.49.    }    
50 50.50.</script>    
51 51.51.</body>    

 

转载于:https://www.cnblogs.com/YangFei-wow/archive/2012/07/05/2577677.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值