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


当前回答

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

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

其他回答

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

$(document).height()

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

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

例如:

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

之前的回答中提到的脚本,比如:

$("body, html").animate({
    scrollTop: $(document).height()
}, 400)

or

((窗口).scrollTop美元(文档).height ());

将不会在Chrome中工作,并将在Safari中跳跃,以防html标签在CSS中溢出:auto;属性集。我花了将近一个小时才弄明白。

如果你想要一个漂亮的缓慢动画滚动,对于任何带有href="#bottom"的锚,这将滚动到底部:

$("a[href='#bottom']").click(function() {
  $("html, body").animate({ scrollTop: $(document).height() }, "slow");
  return false;
});

您可以随意更改选择器。

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

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