我如何使用jquery向下滚动到iframe或页面的底部?


当前回答

这个对我很有用:

var elem = $('#box');
if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()) {
  // We're at the bottom.
}

其他回答

scrollTop()返回从可滚动区域的视图中隐藏的像素数,因此给它:

$(document).height()

会超出页面的底部。为了让滚动实际“停止”在页面底部,需要减去当前浏览器窗口的高度。这将允许在需要时使用easing,所以它变成:

$('html, body').animate({ 
   scrollTop: $(document).height()-$(window).height()}, 
   1400, 
   "easeOutQuint"
);

这个对我很有用:

var elem = $('#box');
if (elem[0].scrollHeight - elem.scrollTop() == elem.outerHeight()) {
  // We're at the bottom.
}
$('.block').scrollTop($('.block')[0].scrollHeight);

我使用此代码在新消息到达时滚动聊天。

一个简单的函数,跳到整个页面的底部(立即滚动)。它使用内置的. scrolltop()。我还没有尝试将其用于单独的页面元素。

function jumpToPageBottom() {
    $('html, body').scrollTop( $(document).height() - $(window).height() );
}

例如:

$('html, body').scrollTop($(document).height());