简体   繁体   English

FancyBox在加载ajax的DIV中不起作用

[英]FancyBox not working inside an ajax loaded DIV

I've seen a couple of other issues like this and read through them but still couldn't solve my problem. 我已经看过其他几个类似的问题,并仔细阅读了这些问题,但仍然无法解决我的问题。

I have some DIVs loaded through ajax on a page, within one of which are links that I want to open with Fancybox. 我在页面上通过ajax加载了一些DIV,其中一个是我想使用Fancybox打开的链接。 Strangely, if I open the DIV with the Fancybox link in FIRST, it works fine. 奇怪的是,如果我使用FIRST中的Fancybox链接打开DIV,它可以正常工作。 However if I open any of the other DIVs, then open the one with the Fancybox link, it doesn't work. 但是,如果我打开任何其他DIV,然后使用Fancybox链接打开一个,则无法使用。

Similarly, if I open the Fancybox DIV, then another, then go back, it doesn't work. 同样,如果我打开Fancybox DIV,然后再打开另一个,然后再返回,则不起作用。

$("a.result").fancybox({'transitionIn':'fade'});

That's all I have at the bottom of the DIV with the Fancybox links. 这就是我用Fancybox链接放在DIV底部的全部内容。 I originally tried with document.ready() too, but it's just the same... 我最初也尝试了document.ready(),但是还是一样的...

Any ideas what I should be doing? 有什么想法我应该做什么?

By replacing the DIV you're removing the original element that had the Fancybox event attached to it. 通过替换DIV,您将删除附加了Fancybox事件的原始元素。 If you call $("a.result").fancybox({'transitionIn':'fade'}); 如果您调用$("a.result").fancybox({'transitionIn':'fade'}); in the success function of your ajax call it will re-attach the events and the Fancybox should load. 在ajax调用的成功函数中,它将重新附加事件,并且Fancybox应该加载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM