我的页面上有一个div:
<div id='div1' style='overflow:scroll;overflow-x:hidden;max-height:200px;'></div>
我怎样才能使div滚动到div的底部??不是页面,只是DIV。
我的页面上有一个div:
<div id='div1' style='overflow:scroll;overflow-x:hidden;max-height:200px;'></div>
我怎样才能使div滚动到div的底部??不是页面,只是DIV。
当前回答
我在一个遗留代码库中工作,试图迁移到Vue。
在我的特定情况下(在引导模式中包装的可滚动div), v-if显示了新内容,我希望页面向下滚动到这些内容。为了让这种行为工作,我必须等待vue完成重新渲染,然后使用jQuery滚动到模态的底部。
所以…
this.$nextTick(function() {
$('#thing')[0].scrollTop = $('#thing')[0].scrollHeight;
})
其他回答
滚动窗口到目标div的底部。
function scrollToBottom(id){
div_height = $("#"+id).height();
div_offset = $("#"+id).offset().top;
window_height = $(window).height();
$('html,body').animate({
scrollTop: div_offset-window_height+div_height
},'slow');
}
scrollToBottom('call_div_id');
$(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;
})
你可以使用下面的代码滚动到底部的div页面加载。
$(document).ready(function(){
$('div').scrollTop($('div').scrollHeight);
});
试试这个:
$('#div1').scrollTop( $('#div1').height() )