ajax调用后没有附加到链接的fancybox
我使用fancybox通过在链接中包含较小的照片来显示较大的照片。 这很好用。 工具提示jQuery应用程序存在小问题,这就是为什么我得到var’title_from_alt’并用它设置fancybox标题。 它并不那么重要。
好的,现在我通过AJAX调用检索页面。 在部分,有类’fancyboxfoto’的新链接。 但是这些新添加的链接没有附加到它们的fancybox。
我读过.on和.live等等,但他们似乎想要一个事件(比如’click’)但是在下面的代码中我没有看到一个’click’事件。 该怎么办!?
jQuery(document).ready(function($){ //fancybox var title_from_alt = $("a.fancyboxfoto").attr("alt"); $("a.fancyboxfoto").fancybox({ 'titlePosition' : 'over', 'onComplete' : function() { $("#fancybox-wrap").hover(function() { $("#fancybox-title").show(); }, function() { $("#fancybox-title").hide(); }); }, 'overlayColor' : '#000', 'title' : title_from_alt, 'overlayOpacity' : 0.9, 'showCloseButton' : 'true', 'autoScale' : 'true', 'autoDimensions' : 'true' }); });
HTML
fancybox v1.3.x不支持动态添加的元素。
你可以在这里找到一个解决方法 (包括例子)
顺便说一句,如果使用该方法,则不需要“ 通过AJAX检索新的DOM元素后再次初始化fancybox ”
在通过AJAX检索新的DOM元素后,您应该再次初始化fancybox。