我的页面上有一个div:

<div id='div1' style='overflow:scroll;overflow-x:hidden;max-height:200px;'></div>

我怎样才能使div滚动到div的底部??不是页面,只是DIV。


当前回答

你可以使用下面的代码滚动到底部的div页面加载。

$(document).ready(function(){
  $('div').scrollTop($('div').scrollHeight);
});

其他回答

$(window).load(function() {
  $("html, body").animate({ scrollTop: $(document).height() }, 1000);
});

这将获取页面的高度,并在窗口加载后向下滚动页面。一旦页面准备好,将1000更改为您需要的任何速度。

我在一个遗留代码库中工作,试图迁移到Vue。

在我的特定情况下(在引导模式中包装的可滚动div), v-if显示了新内容,我希望页面向下滚动到这些内容。为了让这种行为工作,我必须等待vue完成重新渲染,然后使用jQuery滚动到模态的底部。

所以…

this.$nextTick(function() {
    $('#thing')[0].scrollTop = $('#thing')[0].scrollHeight;
})

试试这个:

$('#div1').scrollTop( $('#div1').height() )

你可以使用下面的代码滚动到底部的div页面加载。

$(document).ready(function(){
  $('div').scrollTop($('div').scrollHeight);
});

下面的方法会有用。请注意[0]和scrollHeight

$("#myDiv").animate({ scrollTop: $("#myDiv")[0].scrollHeight }, 1000);