在页面加载时滚动到Div的底部(jQuery) [英] Scroll to bottom of Div on page load (jQuery)

查看:154
本文介绍了在页面加载时滚动到Div的底部(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网页上有一个div:

I have a div on my page:

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

如何让div滚动到div的底部?不是页面,只是DIV。

How can I make the div scroll to the bottom of the div?? Not the page, just the DIV.

推荐答案

这里的其他解决方案实际上并不适用于包含大量内容的div - 它最大化滚动到div的高度(而不是div的 content 的高度)。所以他们会工作,除非你的内容的高度超过div的两倍以上。

The other solutions here don't actually work for divs with lots of content -- it "maxes out" scrolling down to the height of the div (instead of the height of the content of the div). So they'll work, unless you have more than double the div's height in content inside of it.

这是正确的版本:

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

或jQuery 1.6+版本:

or jQuery 1.6+ version:

var d = $('#div1');
d.scrollTop(d.prop("scrollHeight"));

动画:

Or animated:

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

这篇关于在页面加载时滚动到Div的底部(jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆