jScrollPane 不位于底部
我在我设计的一个简单的聊天界面中使用 jScrollPane 作为滚动条。我这里遇到的问题是 jScrollPane 不会自动滚动到底部。 jScrollPane 确实有一个方便的选项“stickToBottom”,我已将其设置为 true,而且我已将“autoReinitalise”设置为 true,因为内容会动态添加到特定的 div。现在,一旦聊天框被填满并添加了滚动条,我希望 jScrollPane 会自动滚动到底部并粘在那里。但事实并非如此。我首先必须手动滚动到底部,然后它会粘在那里。因此,我尝试创建一个高度比其父级(具有滚动条)高 1 像素的内部 div,以便从一开始滚动条就可见。然后,通过 api,我在 Y 轴上滚动到 100%,以便滚动手柄完全向下。但在这种情况下,当我的聊天框被填满并且内容超出可用空间时,滚动条不会粘在底部,它甚至会再次滚动到几乎顶部。
我设置了一个非常简单的测试页,但存在此问题:
http://www.webtrail.nl/jscrollpane -示例
希望有人可以帮助我。谢谢!
I use jScrollPane for the scrollbars in a simple chat interface I designed. The issue I have here is that jScrollPane doesn't scroll to the bottom automatically. jScrollPane does have a handy option 'stickToBottom' that I've set to true and also I've set 'autoReinitalise' to true since content gets added to the specific div dynamically. Now, as soon as the chatbox is getting filled and scrollbars are added I expected jScrollPane to automatically scroll to the bottom and stick there. But this isn't the case. I first manually have to scroll to the bottom and then it will stick there. So I tried to create an innerdiv with the height 1 pixel more than it's parent (that has the scrollbars) so that from the beginning scrollbars are visible. Via the api I then scroll to 100% over the Y-axis so that the scrollhandle is totally down. But also in this case when my chatbox is being filled and content is exceeding the available space the scrollbar doesn't stick to the bottom, it even scrolls almost to the top again.
I've set up a very simple testpage that has this issue:
http://www.webtrail.nl/jscrollpane-example
Hope someone can help me out here. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
默认情况下,您应该启用
maintainPosition
和stickToBottom
,但棘手的部分是仅调用scrollToBottom()
一次,此时内容将完全占据屏幕滚动 div 的高度,您应该这样做,因为您仍然希望maintainPosition
功能正常工作(这样,如果用户滚动到顶部,即使有新内容到达,他也会停留在那里)。如果多次调用
scrollToBottom()
,每次都会滚动到底部(从而消除maintainPosition
功能)。如果初始内容大于页面的高度,那么您可以在页面加载时调用
scrollToBottom
,但如果不是,您需要计算内容大小何时 = 滚动 div 高度。我采取了一种方法来说明这一点(当我添加 24 个 div 时,div 需要滚动,因此我调用
scrollToBottom
):完整源代码:http://jsfiddle.net/STHgr/37/
You should have
maintainPosition
andstickToBottom
enabled by default, but the tricky part is callingscrollToBottom()
only once, when the content will fully occupy the scroll div's height, and you should be doing because you still want themaintainPosition
feature to work (so that if the user scrolls to the top, he stays there even if new content arrives).If you call
scrollToBottom()
multiple times, it will scroll to the bottom each time (thus eliminating themaintainPosition
feature).If the initial content is bigger than the height of the page then you can call
scrollToBottom
on page load, but if not you need to calculate when the content size = scroll div height.I made an approach to exemplify this (when I add 24 divs the div needs scrolling so I call
scrollToBottom
then):Full source: http://jsfiddle.net/STHgr/37/