如何检测浏览器滚动到每个元素的底部
How to detect browser scroll reached to bottom of each element?
我有5个不同高度的div元素。示例:
<body>
<div id="d1" style="height: 800px; float: left; width:100%;"></div>
<div id="d2" style="height: 920px; float: left; width:100%;"></div>
<div id="d3" style="height: 876px; float: left; width:100%;"></div>
<div id="d4" style="height: 1200px; float: left; width:100%;"></div>
<div id="d5" style="height: 1105px; float: left; width:100%;"></div>
</body>
div的最小高度等于窗口高度。
如何检测用户何时滚动到每个元素的底部?
谢谢,
var winHeight = $(window).height();
if ($(document).scrollTop() >= $('#d5').offset().top + $('#d5').height() - winHeight) {
// scrolled to the bottom of d5 div.
} else if ($(document).scrollTop() >= $('#d4').offset().top + $('#d4').height() - winHeight) {
// scrolled to the bottom of d4 div.
} else if ($(document).scrollTop() >= $('#d3').offset().top + $('#d3').height() - winHeight) {
// scrolled to the bottom of d3 div.
} else if ($(document).scrollTop() >= $('#d2').offset().top + $('#d2').height() - winHeight) {
// scrolled to the bottom of d2 div.
} else if ($(document).scrollTop() >= $('#d1').offset().top + $('#d1').height() - winHeight) {
// scrolled to the bottom of d1 div.
}
我想jquery.viewport可以解决您的问题。
相关文章:
- 将视口底部滚动到元素底部
- 如何使一个元素从网页的顶部跳到底部再跳回到顶部
- 使用JQuery从窗口底部修复元素
- 如何用javascript滚动html中pdf对象元素的底部
- 滚动到页面的底部元素
- 将元素与窗口底部对齐,但允许滚动到下面的内容
- 如何使用 jQuery 检测元素的顶部靠近浏览器底部
- 避免元素跳转到页面底部的正确方法
- 元素位于底部并从底部截止
- 使元素在页面底部消失
- 如何使用 jquery 在滚动到底部时正确从元素中删除隐藏类
- 如何让我的导航栏在到达元素时粘在元素的底部
- jQuery或JS,使元素离开屏幕底部并在顶部输入
- 如何检测浏览器滚动到每个元素的底部
- 将元素滚动到页面底部的视图中
- 当光标到达底部时,有没有办法防止contentEditable元素滚动
- 当滚动到顶部而不是底部时添加元素
- 用户到达页面底部.元素逐渐消失
- 如何将文本环绕在父元素底部的图像
- 当元素底部边缘滚动到视图中时,固定元素