首页 > Web开发 > 详细

js滚动条滚动到底部和顶部

时间:2017-10-18 21:22:11      阅读:397      评论:0      收藏:0      [点我收藏+]
 
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <title></title>  
  5.     <style type="text/css">  
  6.         .scrolldiv{  
  7.             width: 500px;  
  8.             height: 400px;  
  9.             margin: 1000px auto 100px auto;  
  10.             background: #f00;  
  11.         }  
  12.     </style>  
  13. </head>  
  14. <body>  
  15. <div class="scrolldiv"></div>  
  16.   
  17.   
  18. <script type="text/javascript">  
  19.     function scrollBottomOrTop(){  
  20.         var clients=window.innerHeight || document.documentElement.clientHeight||document.body.clientHeight;  
  21.         var scrollTop=document.body.scrollTop;  
  22.         var wholeHeight=document.body.scrollHeight;  
  23.         if(clients+scrollTop>=wholeHeight){  
  24.             alert(‘我到底部了‘);  
  25.         }  
  26.         if(scrollTop==0){  
  27.             alert(‘我到顶部了‘);  
  28.         }  
  29.     }  
  30.     window.onscroll=scrollBottomOrTop;  
  31. </script>  
  32. </body>  
  33. </html>  

js滚动条滚动到底部和顶部

原文:http://www.cnblogs.com/chaofei/p/7688924.html

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