我想每秒刷新一个 div。该 div 由 ready 函数滚动到底部。我该怎么做?

huangapple go评论53阅读模式
英文:

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);

huangapple
  • 本文由 发表于 2023年4月19日 15:47:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76051926.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定