JScrollPane 无法正确处理隐藏内容

发布于 2024-12-29 14:59:14 字数 945 浏览 0 评论 0原文

我在我的网站上安装了 jScrollPane 但无法使其工作。

我的网站的工作原理如下:从主页,使用 jQuery 的 load() 方法动态加载页面。在我加载的页面中,我有以下脚本来启动 jScrollPane:

$(function(){
    $('.scroll-pane').jScrollPane();
});

这似乎被调用。我想到目前为止还没有问题。问题是页面一开始不够长,不需要滚动条。我隐藏了仅在特定操作上显示的内容(即单击按钮显示特定段落的内容),并且当我单击以显示隐藏 div 的内容时,滚动条不会出现。

我还尝试在显示新内容时调用 $('.scroll-pane').jScrollPane(); (即触发 .show() 的事件)在隐藏的 div 上,我还调用了 $('.scroll-pane').jScrollPane();) 但我也没有成功。

有人可以帮助我吗?

谢谢

编辑:

我忘了提及页面的结构:我有一个 div ,它有 class="scroll-pane" 并随页面加载一起加载,它包含单击特定区域时会显示小的隐藏 div。我想使用滚动窗格类向 div 添加一个滚动条,以便使显示的 div 的内容可滚动(现在内容保持在 div 的大小中,但它不可滚动,因为没有 jScrollPane 滚动条)所示)。

更新:

我尝试将 $('.scroll-pane').jScrollPane(); 放入 div 的 .show() 方法的回调中,并尝试将 class="scroll-pane" 放入出现的那些 div 中,但同样没有显示任何内容(滚动条不出现并且 div 不可滚动)。

I installed jScrollPane on my website and can't make it work.

My website works as follows: from the main page, pages are loaded dynamically using jQuery's load() method. In the page I load I have the following script to launch jScrollPane:

$(function(){
    $('.scroll-pane').jScrollPane();
});

Which seems to be called. No problems so far I guess. The problem is that the page, at the beginning, is not long enough to need a scrollbar. I have hidden content that shows up only on specific actions (i.e. clicking on a button shows the content of a certain paragraph), and when I click to show the content of a hidden div, the scrollbar doesn't appear.

I also tried to call $('.scroll-pane').jScrollPane(); as I show the new content (i.e. in the event that triggers .show() on the hidden div I also call $('.scroll-pane').jScrollPane();) but I had no success with that either.

Can anyone help me?

Thanks

EDIT:

I forgot to mention the structure of the page: I have a div which has class="scroll-pane" and is loaded with the page load and it contains small hidden divs that show up when clicking on particular areas. I would like to add a scroll bar to the div with the class scroll-pane in order to make the content of the showed div scrollable (right now the content stays in the size of the div but it's not scrollable since no jScrollPane scroll bar is shown).

Update:

I tried to put $('.scroll-pane').jScrollPane(); in the callback of the .show() method of my divs and tried to put class="scroll-pane" to those divs that appear, but again nothing is shown (the scroll bar doesn't appear and the div is not scrollable).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

嗼ふ静 2025-01-05 14:59:14

查看插件开发人员提供的演示

http://jscrollpane.kelvinluck.com/examples/隐形.html

当元素首次显示时,您只需(重新)初始化
滚动窗格(或者如果您愿意,您甚至可以使用 autoReinitialise)和
它的宽度和高度将被正确计算。

您所需要的只是

$(function(){
    $('.scroll-pane').jScrollPane({autoReinitialise: true});
});

并且可能是该插件的最新版本

Check this demo provided by the developer of the plugin

http://jscrollpane.kelvinluck.com/examples/invisibles.html

When the element is first shown you simply have to (re)initialise the
scrollpane (or you could even use autoReinitialise if you like) and
its width and height will be calculated correctly.

All that you need is

$(function(){
    $('.scroll-pane').jScrollPane({autoReinitialise: true});
});

and may be the recent version of the plugin

请你别敷衍 2025-01-05 14:59:14

我建议使用 css 可见性属性而不是自动重新初始化。每次调用 show() 方法时,jScrollPane 都会重新初始化自身。这需要时间并且会对动画产生影响。

如果您使用,比如说,slide..() 方法,那么动画会正常启动,但可滚动容器(及其元素)会稍后出现,这看起来很糟糕。

var wrapper = jQuery('#gallery-album-preview-wrapper');
if (wrapper.css("visibility") == "hidden") {
    wrapper.css("visibility", "visible").css("display", "none");
}
if (wrapper.is(":hidden")) {
    wrapper.slideDown(1000);
} else {
    wrapper.slideUp(1000);
}

I suggest to use css visibility property instead auto reinitialising. Each time you call show() method, jScrollPane reinitialises itself. This takes time and has impact on animation.

If you use, say, slide..() methods, then animation starts properly, but scrollable container (and its elements) appears little bit later, and that looks bad.

var wrapper = jQuery('#gallery-album-preview-wrapper');
if (wrapper.css("visibility") == "hidden") {
    wrapper.css("visibility", "visible").css("display", "none");
}
if (wrapper.is(":hidden")) {
    wrapper.slideDown(1000);
} else {
    wrapper.slideUp(1000);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文