检测是否滚动到底部

Detect if scrolled to bottom

本文关键字:底部 滚动 是否 检测      更新时间:2023-09-26

如何通过使用按钮单击功能(而不是滚动箭头按钮)来检测div是否滚动到底部?

。因此,当单击$('#checkBottom').时,如果$('#items')滚动到div的底部,它将输出警报。当$('#checkBottom').被点击时,如果$('#items')没有滚动到div的底部,它不输出警报。

金桥:

$('#checkBottom').on('click', function () {
    alert("yes, it has reached the bottom of the scroll");
});

滚动div结构示例:

<div id="Wrapper">
    <div id="itemWrapper">
        <div id="items">
            <div class="content">
                <input type="image" src="http://img42.com/p1puE+" />
            </div>
            <div class="content">
                <input type="image" src="http://img42.com/p1puE+" />
            </div>
            <div class="content">
                <input type="image" src="http://img42.com/p1puE+" />
            </div>
        </div>
    </div>
</div>
$('#checkBottom').on('click', function () {
  var wrapper = document.getElementById('Wrapper');
  if (wrapper.scrollTop + wrapper.offsetHeight >= wrapper.scrollHeight) {
    alert("yes, it has reached the bottom of the scroll");
  }
});