使用 jquery live 更新滚动条

发布于 2024-11-15 10:05:41 字数 580 浏览 3 评论 0原文

我正在开发一个网页,它使用折叠 div 元素来扩展和收缩每个标题的内容。我还使用了一个自定义滚动条,每当发生展开或收缩事件时都需要更新该滚动条。 到目前为止,我想出的解决方案是使用 jquery 的 live,如下所示:

jQuery('#accordion_sp1_id139').live('click',function(){ myScrollBar.update();});

所以基本上我告诉它在主手风琴 div 内发生点击事件时更新滚动条。

我的问题是,第一次在该 div 内单击任何内容时这不起作用,但它适用于任何后续点击。无论如何,有没有办法让它在第一次点击时也能工作。

这是出现问题的页面:https://www.arrowandbranch.com/media/press 我使用的滚动条是取自 http://www.baijs.nl/tinyscrollbar/ 的 jquery 插件

I am working on a webpage which uses accordion div elements to expand and contract the content of each title. I am also using a custom scrollbar that needs to get updated whenever either an expand or a contract event happens.
So far the solution i came up with is to use jquery's live like below:

jQuery('#accordion_sp1_id139').live('click',function(){ myScrollBar.update();});

So basically i am telling it to update the scrollbar anytime a click event occurs within the main accordion div.

My problem is that this doesn't work the first time anything is clicked inside that div, but it works on any subsequent clicks. Is there anyway to make it work on the first click also.

Here is the page with the problem: https://www.arrowandbranch.com/media/press
the scrollbar i use is jquery plugin taken from http://www.baijs.nl/tinyscrollbar/

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

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

发布评论

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

评论(2

心凉 2024-11-22 10:05:41

我相信这里发生的事情是您的 Accordion 容器的点击事件直接触发在单击事件启动手风琴动画之后但在容器展开之前。您需要将 myScrollBar.update() 调用设置为在 Accordion 动画完成后进行,这在 MooTools Docs - Fx/Fx.Accordion (尽管一开始并不十分突出)

在您的 Accordion 脚本中添加用于运行滚动条更新的 onComplete: 设置...

var myAccordion139 = new Accordion(document.getElements('#accordion_sp1_id139 .toggler'), document.getElements('#accordion_sp1_id139 .sp-accordion-inner'), {
    opacity: true,
            display:-1,
            alwaysHide: true,       
    onActive: function(toggler){
        toggler.addClass('active');
    },
    onBackground: function(toggler){
        toggler.removeClass('active');
    },
    onComplete: function(toggler) {
        myScrollBar.update();
    }
});

I believe what's going on here is your click event for your Accordion container is firing directly after the click event to start the accordion animation but before the container is expanded. You'll need to set your myScrollBar.update() call to happen after the Accordion animation has completed which is mentioned in the documentation for the MooTools Docs - Fx/Fx.Accordion (although it doesn't quite stand out at first)

in your Accordion script add an onComplete: setting to run your scrollbar update...

var myAccordion139 = new Accordion(document.getElements('#accordion_sp1_id139 .toggler'), document.getElements('#accordion_sp1_id139 .sp-accordion-inner'), {
    opacity: true,
            display:-1,
            alwaysHide: true,       
    onActive: function(toggler){
        toggler.addClass('active');
    },
    onBackground: function(toggler){
        toggler.removeClass('active');
    },
    onComplete: function(toggler) {
        myScrollBar.update();
    }
});
诠释孤独 2024-11-22 10:05:41

一个简单的解决方案是更新手风琴打开事件的处理程序中的滚动条。在查看您的代码时,如果您要在“press”页面上编写如下所示的 JavaScript:

    onActive: function(toggler){
      toggler.addClass('active');
      myScrollBar.update();
    },

我的猜测是它会起作用,假设 myScrollBar 变量在该函数的范围内。

A simple solution would be to update the scrollbar in the handler for the accordion open event. In looking at your code, if you were to make the javascript on the "press" page like this:

    onActive: function(toggler){
      toggler.addClass('active');
      myScrollBar.update();
    },

My guess is that it would work, assuming that the myScrollBar variable is in the scope of that function.

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