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

 
  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>  
posted @ 2017-10-18 21:00  逗比煎饼侠  阅读(1174)  评论(0编辑  收藏  举报