chrome浏览器滚动到底部无法加载,实际上没到底部,差一点点下不去,怎么解决?

来源:3-2 网页滚动到顶部或者底部

qq_答案_8

2019-01-31 18:15

<!DOCTYPE>
<html>
<head>
 <meta charset="UTF-8">
 <title>网页滚动到底部或者顶部加载</title>
 <style type="text/css" rel="stylesheet">
 *{margin:0;padding:0;}
 .scrolldiv{
  width: 800px;
  height: 600px;
  margin:300px auto 100px auto;
  background-color: #FF0000;
 }
</style>
</head><body>
 <div class="scrolldiv"></div>
<!--js写法-->
 <script type="text/javascript">
 function scrollBottomOrTop(){
  var clients=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight;
  //console.log(clients);
  var scrollTops=document.body.scrollTop;
  //console.log(scrollTops);
  var wholeHeight=document.body.scrollHeight||document.documentElement.scrollHeight;
  //console.log(wholeHeight);
  if(clients+scrollTops>=wholeHeight)
  {
   alert("bottom")
  }
  if(scrollTops==0){
   alert("top")
  }
 }
 window.onscroll= scrollBottomOrTop;
 </script></body>
</html>

写回答 关注

1回答

  • 手机用户曾小乱
    2019-07-20 21:27:53

    我试了上述代码可以运行。

JS/jQuery宽高的理解和应用

js/jquery各种宽高的理解,结合实例对宽高做一些简单的应用

34044 学习 · 59 问题

查看课程