如何检查滚动条是否在底部

如何检查滚动条是否位于底部? 使用JQuery或JavaScript

您可以找到滚动容器的高度,然后将其与滚动位置进行比较。 如果它们是相同的,那么你已经到了底部。

$(document).ready(function() { $('div').scroll(function() { var div = $(this); if (div.height() == div.scrollTop() + 1) //scrollTop is 0 based { alert('Reached the bottom!"); } }); });

编辑:在js小提琴中进行一点测试,我意识到以前的版本不正确。 您可以使用DOM属性来查找有多少滚动,使用元素的高度执行一些数学运算

  var div = $(this); if (div[0].scrollHeight - div.scrollTop() == div.height()) { alert('Reached the bottom!'); } 

http://jsfiddle.net/Aet2x/1/

这对我有用(使用jQuery):

 $(document).ready(function(){ $('div').scroll(function(){ //scrollTop refers to the top of the scroll position, which will be scrollHeight - offsetHeight if(this.scrollTop == (this.scrollHeight - this.offsetHeight)) { console.log("Top of the bottom reached!"); } }); }); 

从这里开始 。

您可以检查元素scrollTop是否等于元素innerHeight

 if($('div').scrollTop() == $('div').innerHeight()){ //Reached the bottom }