英文:
I want to refresh a div every one second. That div is scrolled to bottom by ready function. How can I do this?
问题
I am using this code to set scrolled to bottom when the page lodes -
$(document).ready(function(){
$('#chat_message_inner_container').scrollTop( $('#chat_message_inner_container')[0].scrollHeight);
});
And I want to use this code also -
setInterval(function()
{
$('#chat_message_inner_container').load(location.href + " #chat_message_inner_container");
},1000);
But it is not working.
How can I do this ?
英文:
I am using this code to set scrolled to bottom when the page lodes -
$(document).ready(function(){
$('#chat_message_inner_container').scrollTop( $('#chat_message_inner_container')[0].scrollHeight);
});
And I want to use this code also -
setInterval(function()
{
$('#chat_message_inner_container').load(location.href + " #chat_message_inner_container");
},1000);
But it is not working.
How can I do this ?
答案1
得分: 1
你的滚动指令应在加载函数回调上执行,而不是在准备就绪时执行。
setInterval(function () {
$('#chat_message_inner_container').load(location.href + "#chat_message_inner_container", {}, function () {
$('#chat_message_inner_container').scrollTop($('#chat_message_inner_container')[0].scrollHeight);
});
}, 1000);
英文:
your scroll instruction should be executed on the load function callback and not on ready
setInterval(function () {
$('#chat_message_inner_container').load(location.href + "#chat_message_inner_container", {}, function () {
$('#chat_message_inner_container').scrollTop($('#chat_message_inner_container')[0].scrollHeight);
});
}, 1000);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论