码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-10-18 21:39:45      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:ext   nts   cli   tle   height   top   tools   attribute   text   

 
  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滚动条滚动到底部和顶部

标签:ext   nts   cli   tle   height   top   tools   attribute   text   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!