Javascript 如何向下滚动到div标签内项目的底部?

Javascript 如何向下滚动到div标签内项目的底部?,javascript,jquery,jsp,Javascript,Jquery,Jsp,此代码仅在浏览器右侧的主滚动条上有效,但在div标记内不起作用,有人能告诉我如何使位于div内的内容滚动到底部吗 使用jQuery,您可以这样做: div#hahaha{ background-color: #EEEEEE; position: absolute; width:500px; height:200px; overflow-y: scroll; } 或者,如果您想为其设置动画: var bottom= $('div').height()+$(

此代码仅在浏览器右侧的主滚动条上有效,但在div标记内不起作用,有人能告诉我如何使位于div内的内容滚动到底部吗

使用jQuery,您可以这样做:

div#hahaha{
    background-color: #EEEEEE;
    position: absolute;
    width:500px;
    height:200px;
    overflow-y: scroll;
}
或者,如果您想为其设置动画:

var bottom= $('div').height()+$('div').prop('scrollHeight');    
$('div').scrollTop(bottom);

下面是一个示例,您可以使用或查找要滚动到的div的位置

使用
offset

usign
位置

var bottom= $('div').height()+$('div').prop('scrollHeight');    
$('div').scrollTop(bottom);
var bottom= $('div').height()+$('div').prop('scrollHeight');    
$('div').animate({scrollTop:bottom},500);
$(window).load(function () {
     var pos = $('.scrollhere').position()  // or .offset
     var toppos = pos.top
     $('#scrolling').stop().animate({
         'scrollTop': toppos
     }, 1000)
 })