js捕捉下拉到底部
【摘要】 前言通过js代码捕捉网页已经下拉到底部,触发一个js请求。代码<!DOCTYPE html><html><head> <title>拉到底部测试</title> <meta charset="gbk"> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> .item{ ...
前言
通过js代码捕捉网页已经下拉到底部,触发一个js请求。
代码
<!DOCTYPE html><html><head>
<title>拉到底部测试</title>
<meta charset="gbk">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.item{ width: 300px; height: 100px; background: #333333; margin-top: 10px;
} </style><body><div data-role="page" data-theme="b">
<div data-role="header"></div>
<div data-role="content">
<script>
//文档高度
function getDocumentTop() { var scrollTop = 0, bodyScrollTop = 0, documentScrollTop = 0; if (document.body) {
bodyScrollTop = document.body.scrollTop;
} if (document.documentElement) {
documentScrollTop = document.documentElement.scrollTop;
}
scrollTop = (bodyScrollTop - documentScrollTop > 0) ? bodyScrollTop : documentScrollTop; return scrollTop;
} //可视窗口高度
function getWindowHeight() { var windowHeight = 0; if (document.compatMode == "CSS1Compat") {
windowHeight = document.documentElement.clientHeight;
} else {
windowHeight = document.body.clientHeight;
} return windowHeight;
} //滚动条滚动高度
function getScrollHeight() { var scrollHeight = 0, bodyScrollHeight = 0, documentScrollHeight = 0; if (document.body) {
bodyScrollHeight = document.body.scrollHeight;
} if (document.documentElement) {
documentScrollHeight = document.documentElement.scrollHeight;
}
scrollHeight = (bodyScrollHeight - documentScrollHeight > 0) ? bodyScrollHeight : documentScrollHeight; return scrollHeight;
} window.onscroll = function () { console.log(getScrollHeight() +"=?" + getWindowHeight() +"+" + getDocumentTop()) if(getScrollHeight() == getWindowHeight() + getDocumentTop()){ console.log("底裤出来了")
}
} </script>
<div class="list">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div></body></html>
执行效果
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)