js滾動條滾動到底部和頂部
阿新 • • 發佈:2017-10-18
var margin wid XML oct clas scrip scrolltop css
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <style type="text/css">
- .scrolldiv{
- width: 500px;
- height: 400px;
- margin: 1000px auto 100px auto;
- background: #f00;
- }
- </style>
- </head>
- <body>
- <div class="scrolldiv"></div>
- <script type="text/javascript">
- function scrollBottomOrTop(){
- var clients=window.innerHeight || document.documentElement.clientHeight||document.body.clientHeight;
- var scrollTop=document.body.scrollTop;
- var wholeHeight=document.body.scrollHeight;
- if(clients+scrollTop>=wholeHeight){
- alert(‘我到底部了‘);
- }
- if(scrollTop==0){
- alert(‘我到頂部了‘);
- }
- }
- window.onscroll=scrollBottomOrTop;
- </script>
- </body>
- </html>
js滾動條滾動到底部和頂部