简体   繁体   English

充电后将div滚动到底部

[英]Scroll div to bottom when recharged

I have a script that automatically reloads the contents of a div. 我有一个脚本,可以自动重新加载div的内容。 The code works, however there is one thing I can not solve: 该代码有效,但是有一件事我无法解决:

The first time I load the page the scrollbar goes to the bottom of the div (and that's fine), but when you update with the script (from the second onwards) the scrollbar stays up. 第一次加载页面时,滚动条会转到div的底部(这很好),但是当您使用脚本进行更新(从第二个开始)时,滚动条会停留在上面。

 <script> setInterval("my_function1();",5000); $("#interno_chat").scrollTop($("#interno_chat")[0].scrollHeight); function my_function1(){ $('#interno_chat').load(window.location.href + ' #interno_chat'); } </script> 

If i put the scrollTop-scrollHeight in my_function1 the code doesn't work even the first time. 如果我将scrollTop-scrollHeight放置在my_function1中,则即使第一次也无法使用该代码。

Thank you 谢谢

<script>
  setInterval("my_function1();",5000);
  $("#interno_chat").scrollTop($("#interno_chat")[0].scrollHeight);
  function my_function1(){
    $('#interno_chat').load(window.location.href + ' #interno_chat', function() {
        $("#interno_chat").scrollTop($("#interno_chat")[0].scrollHeight);
    });        
  }
</script>

I suspect the issue is that you're not waiting for the content to be loaded. 我怀疑问题是您没有等待内容加载。

See http://api.jquery.com/load/ 参见http://api.jquery.com/load/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM