js滚动到顶部底部代码
1. <!DOCTYPE HTML>
2. <html>
3. <head>
4. <meta charset=UTF-8>
5. <title>SCROLL</title>
6. <style type="text/css">
7. </style>
8. <script type="text/javascript">
9. var goToWhere = function (where)
10. {
11. var me = this;
12. me.site = [];
13. me.sleep = me.sleep ? me.sleep : 16;
14. me.fx = me.fx ? me.fx : 6;
15. clearInterval (me.interval);
16. var dh = document.documentElement.scrollHeight || document.body.scrollHeight;
17. var height = !!where ? dh : 0;
18. me.interval = setInterval (function ()
19. {
20. var top = document.documentElement.scrollTop || document.body.scrollTop;
21. var speed = (height - top) / me.fx;
22. if (speed === me.site[0])
23. {
24. window.scrollTo (0, height);
25. clearInterval (me.interval);
26. }html滚动效果代码
27. window.scrollBy (0, speed);
28. me.site.unshift (speed);
29. }, me.sleep);
30. };
31. </script>
32. </head>
33. <body>
34. <div >5</div>
35. <div >4</div>
36. <div >3</div>
37. <div >2</div>
38. <div >1</div>
39. <div >0</div>
40. <div onclick="goToWhere(0)"
41. >返回顶
部</div>
42. <div onclick="goToWhere(1)"
43. >返回底部</div>
44. </body>
45. </html>
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论