使用 jQuery 将滚动条锁定到页面底部?
我正在客户端使用 jQuery 编写一个日志“tail -f”应用程序。目前,该应用程序的工作方式是每 2 秒向服务器发出一次 AJAX 请求,并将新的日志内容附加到页面上预先存在的
标记 (受到这篇文章的启发)。这一切都很顺利。
我的问题是新内容被附加到页面但没有立即显示。也就是说,所有新的日志消息只是将滚动条推得更高。
我想将滚动条“锁定”在页面底部,以便您可以实时观看所有内容。我最初一直在考虑使用 jScrollPane 来“锁定”滚动条在底部,但现在我想可能有一种更简单的方法来将焦点保持在页面底部......
I am writing a log "tail -f" application using jQuery on the client side. Currently, the application works by making AJAX requests to the server every 2 seconds and appending the new log contents to a pre-existing <PRE>
tag on page (inspired by this post). This is all working beautifully.
My problem is that the new content is appended to the page but not immediately displayed. That is, all new log messages simply push the scroll bar higher.
I would like to keep the scrollbar "locked" to the bottom of the page, so that you can watch all the content appear in real time. I had originally been considering using jScrollPane to "lock" the scrollbar is at the bottom, but now I'm thinking that there might be an easier way to keep the focus on the bottom of the page...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使
scrollTop
=scrollTHeight
检查工作示例 http ://jsfiddle.net/sJshE/3/
You need to make
scrollTop
=scrollTHeight
Check working example at http://jsfiddle.net/sJshE/3/