我的页面上有一个div:

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

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


当前回答

你可以检查scrollHeight和clientHeight与scrollTop滚动到div底部像下面的代码。

$ (' # div ')。滚动(函数(事件){ if ((parseInt($('#div')[0].scrollHeight) - parseInt(this.clientHeight)) == parseInt($('#div').scrollTop())) { Console.log("这是div的滚动底部"); } });

其他回答

当页面加载时,滚动是最大的值。

这是消息框,当用户发送消息时,总是显示最新的聊天,所以滚动值总是最大的。

$('#message').scrollTop($('#message')[0].scrollHeight);

见图片

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

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

jquery的动画(版本> 2.0)

var d = $('#div1');
d.animate({ scrollTop: d.prop('scrollHeight') }, 1000);

你可以检查scrollHeight和clientHeight与scrollTop滚动到div底部像下面的代码。

$ (' # div ')。滚动(函数(事件){ if ((parseInt($('#div')[0].scrollHeight) - parseInt(this.clientHeight)) == parseInt($('#div').scrollTop())) { Console.log("这是div的滚动底部"); } });

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

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