js捕捉下拉到底部
【摘要】 前言
通过js代码捕捉网页已经下拉到底部,触发一个js请求。
代码
<!DOCTYPE html>
<html>
<head>
<title>拉到底部测试</title>
<meta charset="gbk">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style...
前言
通过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>
执行效果
文章来源: www.jianshu.com,作者:Nick_4438,版权归原作者所有,如需转载,请联系作者。
原文链接:www.jianshu.com/p/b486f8297425
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)