失败滚动到IE底部的div

时间:2011-05-21 01:29:44

标签: jquery

我在页面加载时尝试自动滚动到div的底部。它适用于Firefox,但它不适用于IE。如何在IE上加载页面时滚动到div的底部?你可以通过将我的代码粘贴到两个html文件中来测试它。

test5.html:

<div id='div' style='overflow:scroll; height:300px; width:200px; border:1px solid blue; background:yellow;'>
</div>
<script src="javascripts/jquery-1.5.js" type="text/javascript" language="javascript"></script>
<script type="text/javascript">
function showrsp(){
    jQuery.get("test5a.html", function(data) {
        $('#div').append(data); 
        $(document).ready(function(){asd();});
    }); 
};

function asd(){
    $('#div').scrollTop($('#div')[0].scrollHeight);
}

showrsp();
</script>

test5a.html:

<p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" /><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" /><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" /><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<p>asdasdas</p><p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<p>asdasdas</p><p>asdasdas</p>
<p>asdasdas</p><p>asdasdas</p><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<p>asdasdas</p><p>asdasdas</p><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<p>asdasdas</p><p>asdasdas</p><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />
<p>asdasdas</p><p>asdasdas</p><img src="http://2aek.com/inventory/emoticons2/69.gif" border="0" />

如何在执行函数asd()之前等到innerHTML完成呈现内容?

注意:您可以尝试用$(document).ready(function(){asd();});替换我的代码setTimeout("asd();", 3000);等待3秒,然后只执行asd()。所有消息都在3秒内显示,因此滚动条成功位置在底部。不幸的是,我不知道显示所有消息需要多长时间,可能是5或10秒?如何检测内容何时完成呈现?

0 个答案:

没有答案