当 Jquery jScrollPane 重新初始化时,它会返回到顶部。为什么?

发布于 2024-12-19 23:37:28 字数 456 浏览 1 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

雨后咖啡店 2024-12-26 23:37:28

您确定您正在获取所需的数据吗?我不知道这是否有效,但是您尝试过吗:

scroll_bar = $('body>div').jScrollPane(
   {
      autoReinitialise: true,
          showArrows: true,
          maintainPosition: false
   });

scroll_bar.data('jsp');

您通常不会为此使用 .scroll-pane 类,而不是 body>div 选择器吗?

我想也许应该是这样的:

var api = scroll_bar.data('jsp');
api.reinitialise();

Are you sure you're getting the data needed, I have no idea if this works, but have you tried:

scroll_bar = $('body>div').jScrollPane(
   {
      autoReinitialise: true,
          showArrows: true,
          maintainPosition: false
   });

scroll_bar.data('jsp');

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:

var api = scroll_bar.data('jsp');
api.reinitialise();
虐人心 2024-12-26 23:37:28

如果您希望滚动条保留其位置,您应该设置

      maintainPosition: true

另外,尝试像这样重建代码:

            // Use jscrollpane api function to enable reinitialization
            var scrollelement = $('body>div').jScrollPane({ maintainPosition: true});
            var api = scrollelement.data('jsp');
            api.getContentPane().html(result);


            // Needed to apply jscrollpane after change new container type
            api.reinitialise();

希望这有帮助:)

If you want the scroll bar to retain its position, you should set the

      maintainPosition: true

Also, try reconstruct the code like this:

            // Use jscrollpane api function to enable reinitialization
            var scrollelement = $('body>div').jScrollPane({ maintainPosition: true});
            var api = scrollelement.data('jsp');
            api.getContentPane().html(result);


            // Needed to apply jscrollpane after change new container type
            api.reinitialise();

Hope this help :)

溺孤伤于心 2024-12-26 23:37:28

来自 docs

  • maintainPosition [boolean] - 是否想要以下内容滚动窗格在您重新初始化时保持其位置 - 因此当您添加更多内容时它不会滚动(默认 true)

您将其设置为 false

From the docs:

  • maintainPosition [boolean] - Whether you want the contents of the scroll pane to maintain it's position when you re-initialise it - so it doesn't scroll as you add more content (default true)

You set it to false.

迷迭香的记忆 2024-12-26 23:37:28

对于在上述操作后重新初始化时遇到问题的人:

function reinitialiseScrollpane() {

        var settings = {
            maintainPosition: true,
            // add your settings here, below are examples
            arrowButtonSpeed: 1,
            showArrows: true,
            animateScroll: true 
        };

    pane.jScrollPane(settings); 
    var api = pane.data('jsp');
    api.getContentPane().append();
    api.reinitialise();

}

重要的部分是使用设置。如果不重新初始化设置,可能会出现故障。我已将其放入函数调用中,因此只要任何滚动窗格中的内容发生更改,您只需调用此函数即可(假设您将 .scroll-pane 类保留在所有区域中)

For people who have issues re-initializing after the above:

function reinitialiseScrollpane() {

        var settings = {
            maintainPosition: true,
            // add your settings here, below are examples
            arrowButtonSpeed: 1,
            showArrows: true,
            animateScroll: true 
        };

    pane.jScrollPane(settings); 
    var api = pane.data('jsp');
    api.getContentPane().append();
    api.reinitialise();

}

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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文