当 Jquery jScrollPane 重新初始化时,它会返回到顶部。为什么?
我正在使用 jquery 库 jScrollPane 为整个页面设置自定义滚动条。
scroll_bar = $('body>div').jScrollPane(
{
autoReinitialise: true,
showArrows: true,
maintainPosition: false
}).data('jsp');
当在页面底部添加新内容时(当用户位于页面底部时),我调用:
scroll_bar.getContentPane().find(".content").append(some_content);
scroll_bar.reinitialise();
这会重新初始化滚动条,但会将用户带到页面顶部。我希望窗口保持在同一个位置。有什么解决办法吗?
I'm using jquery library jScrollPane to set the custom scroll bar for the whole page.
scroll_bar = $('body>div').jScrollPane(
{
autoReinitialise: true,
showArrows: true,
maintainPosition: false
}).data('jsp');
When new content is added at the bottom of the page (while user is at the bottom of the page), I call:
scroll_bar.getContentPane().find(".content").append(some_content);
scroll_bar.reinitialise();
This reinitializes the scroll bar, but it takes the user to the top of the page. I would like the window to stay at the same spot. Any solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您确定您正在获取所需的数据吗?我不知道这是否有效,但是您尝试过吗:
您通常不会为此使用 .scroll-pane 类,而不是 body>div 选择器吗?
我想也许应该是这样的:
Are you sure you're getting the data needed, I have no idea if this works, but have you tried:
And would'nt you normally use the .scroll-pane class for this, and not the body>div selector ?
I would think maybe it should be something like this:
如果您希望滚动条保留其位置,您应该设置
另外,尝试像这样重建代码:
希望这有帮助:)
If you want the scroll bar to retain its position, you should set the
Also, try reconstruct the code like this:
Hope this help :)
来自 docs:
您将其设置为
false
。From the docs:
You set it to
false
.对于在上述操作后重新初始化时遇到问题的人:
重要的部分是使用设置。如果不重新初始化设置,可能会出现故障。我已将其放入函数调用中,因此只要任何滚动窗格中的内容发生更改,您只需调用此函数即可(假设您将 .scroll-pane 类保留在所有区域中)
For people who have issues re-initializing after the above:
The important part is using the settings. Without re-initialising the settings, it can be glitchy. I have put it in a function call, so you simply call this whenever content is altered in any of your scroll panes (assuming you kept the .scroll-pane class with all regions)