简体   繁体   English

Javascript滚动到底部并不总是滚动到底部

[英]Javascript scroll to bottom doesn't always scroll to bottom

I am using an Iframe which reloads itself every 5 seconds. 我正在使用每5秒钟重新加载一次的Iframe。 It makes use of javascript to automaticly scroll to the bottom because it has too much content to display in one go, but sometimes after a refresh the scroll bar doesn't go down all the way. 它利用javascript自动滚动到底部,因为它一次显示的内容太多,但是有时刷新后滚动条并不会一直向下滚动。 Leaving me scrolling it down myself. 让我自己将其向下滚动。

I really don't know what it is. 我真的不知道那是什么 Maybe one of you has a better peice of Javascript suited for this. 也许你们当中有一个比这更好的Javascript。

Javascript: 使用Javascript:

<script>
var objDiv = document.getElementById("chat");
objDiv.scrollTop = objDiv.scrollHeight;
</script>

The HTML div: HTML div:

<div id="chat" class="scroll">
*Content going on for 150 lines...*
</div>

Thanks in advance. 提前致谢。

You could conceivably create a placeholder div at the bottom of your page, and use this answer to scroll to the bottom of it. 可以想象,您可以在页面底部创建一个占位符div,然后使用此答案滚动到其底部。 This would ensure that you always scroll to that div, rather than what the query perceives as the bottom of the page. 这样可以确保您始终滚动到该div,而不是查询所感知的页面底部。

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

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