使用 jquery live 更新滚动条
我正在开发一个网页,它使用折叠 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信这里发生的事情是您的 Accordion 容器的点击事件直接触发在单击事件启动手风琴动画之后但在容器展开之前。您需要将
myScrollBar.update()
调用设置为在 Accordion 动画完成后进行,这在 MooTools Docs - Fx/Fx.Accordion (尽管一开始并不十分突出)在您的 Accordion 脚本中添加用于运行滚动条更新的
onComplete:
设置...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...一个简单的解决方案是更新手风琴打开事件的处理程序中的滚动条。在查看您的代码时,如果您要在“press”页面上编写如下所示的 JavaScript:
我的猜测是它会起作用,假设 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:
My guess is that it would work, assuming that the myScrollBar variable is in the scope of that function.