当页面加载时,js / jquery滚动到div的底部(IE问题)
我的代码在Firefox上完美运行。当div的内容较少时,它适用于IE,当IE中的div内容过高时,它无法滚动到底部。按钮单击以滚动到底部没有问题,但重新加载页面滚动到底部有问题。如何解决IE问题?如何在IE上加载页面时滚动到div的底部?下面是我的代码,你可以直接复制粘贴来测试它。 :
My codes works perfectly on Firefox. It works on IE when the content of the div is less, it fail to scroll to bottom when the content of div is too high in IE. Button click to scroll to bottom has no problem, but page reloaded to scroll to bottom has the problem. How to fix the IE problem? how to scroll to bottom of div when the page is loaded on IE? Below is my codes, you can copy paste directly to test it. :
<script src="javascripts/jquery-1.5.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript">
function asd(){
d = document.getElementById('div');d.scrollTop = d.scrollHeight;
// $('#div').scrollTop($('#div')[0].scrollHeight);
}
</script>
<button onclick="d = document.getElementById('div');d.scrollTop = d.scrollHeight;">scroll-div</button>
<div id='div' style=' overflow:scroll; height:300px; width:200px; border:1px solid blue; background:blue;'>
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p>
</div>
<script type="text/javascript">
asd();
</script>
等到文档加载完成后:
$(document).ready(function(){asd();});
在文档末尾的某处放置指令与等待准备就绪不一样-event。
Putting an instruction somewhere at the end of the document doesn't be the same like waiting for the ready-event.