1

我想检查是否使用浏览器的滚动条(垂直)将特定 div 的内容滚动到底部并发出警报。我需要知道是否所有内容都向下滚动以获取 div 并向其中添加新内容。

关于如何做的任何建议?

编辑:没有溢出集,我需要通过滚动浏览器窗口来了解 div 内容的结尾。

4

2 回答 2

1

您可以使用一些属性/方法:

$().scrollTop()//how much has been scrolled
$().innerHeight()// inner height of the element
DOMElement.scrollHeight//height of the content of the element

所以你可以像这样得到它

jQuery(
  function($)
  {
    $('#YourDivId').bind('scroll', function()
                              {
                                if($(this).scrollTop() + 
                                   $(this).innerHeight()
                                   >= $(this)[0].scrollHeight)
                                {
                                  alert('end reached');
                                }
    })
  }
);
于 2012-09-06T06:25:28.987 回答
0

你可以这样做:

function IsScrolledToBottom(divID) {
  returnVal = false;

  obj = document.getElementById(divID);

  if ( obj.scrollTop == (obj.scrollHeight - obj.offsetHeight) ) {
    returnVal = true;
  }
  return returnVal;
}

您需要做的就是在 div 元素上调用此函数,如果它已滚动到底部,它将返回 true。

希望这可以帮助。

于 2012-09-06T06:28:32.937 回答