jQuery Facebox 无法与 DD Ajaxtabs 一起使用,有什么解决方案吗?
我费了两个小时的时间,还是没能找出其中的冲突。请帮助我解决此问题。我正在使用 http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/ajaxtabs_suppliment3.htm< /a> 为我的网站创建 ajax 选项卡,并使用 http://defunkt.io/facebox/ 用于模式窗口。但是当我尝试通过ajax选项卡加载facebox链接时,它不会将内容加载到facebox中。但它对于 ajax 选项卡之外的任何链接都可以正常工作。有什么想法吗?
After pullingout my hairs for last 2hours, still I could not find out the conflict. Please help me in troubleshooting this issue. I am using http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/ajaxtabs_suppliment3.htm to create ajax tabs for my sites and also using http://defunkt.io/facebox/ for modal windows. But when I am trying facebox links loaded through the ajax tabs, then its not loading the contents into facebox. But its working fine for any links outside the ajax tabs. Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这仅仅是因为加载到 DOM 中的任何新内容都不会附加任何先前设置的事件处理程序。
因此,在这种情况下,您的 Facebox 插件将在新内容加载到 ajax 选项卡之前进行初始化。因此,本质上facebox插件并不知道这些新链接的存在。
答案是在加载新内容后重新初始化插件。
您需要再次调用:-
因此,一旦新的 ajax 选项卡内容加载到 DOM 中, ...。通过对 ajax 选项卡脚本的简单浏览,我想您可以通过简单地重新初始化 Facebox 插件(如上所示)来轻松解决此问题,方法是将该行添加到一个函数中,每次将任何新内容加载到 ajax 选项卡中时都会调用该函数。
jQuery livequery 插件 初始化 Facebox 插件
或者(而且更简单),您可以使用 这段代码(一旦您在网站上包含了 livequery 脚本:-
Livequery 将在新加载的 Facebox 链接添加到 DOM 时自动检测它们,并为您应用 Facebox 插件。
编辑:
如果仍然如此没有达到预期的效果(虽然我真的不明白为什么不作为实时查询,当我过去使用它是一个梦想)尝试这个肮脏的小技巧来解除绑定并重新绑定facebox每次你在任何facebox链接上。新的或旧的。
This is simply due to the fact that any new content that you load into the DOM will not have any previously set event handlers attached to them.
So in this case your facebox plugin is being initialised prior to the new content being loaded in the ajax tabs. Therefore, essentially the facebox plugin does not know that these new links exists.
The answer is to reinitialise the plugin after the new content has been loaded.
So you need to call:-
...again, once the new ajax tabs content has been loaded into the DOM. From a very brief look over the ajax tabs script I would imagine you could solve this easily by simple reinitialising the facebox plugin (as shown above) by adding that line into a function that gets called everytime any new content is loaded into an ajax tab.
Alternatively (and far more simply) you could initialise the facebox plugin using the jQuery livequery plugin
Using this code (once you have included the livequery script on your site:-
Livequery will then automatically detect the newly loaded facebox links when they are added to the DOM and apply the facebox plugin to them for you.
EDIT:
If this still isn't having the desired effect (though I really can't see why not as live query when I used to use it was a dream) try this dirty little hack to unbind and rebind facebox every time you mouse down. On ANY facebox link new or old.