Jquery 动态链接上的Fancybox
我搜索过类似的主题,但没有一个解决方案适合我。我正在通过Ajax用链接填充我的页面。像这样:Jquery 动态链接上的Fancybox,jquery,ajax,fancybox,Jquery,Ajax,Fancybox,我搜索过类似的主题,但没有一个解决方案适合我。我正在通过Ajax用链接填充我的页面。像这样: $.post('php/common/auction_view/auction_invoices.php', function(data){ $('#auction-invoices').html(data); //Initiate Fancybox on links $("a.example4").fancybox({ 'opacity' : fa
$.post('php/common/auction_view/auction_invoices.php', function(data){
$('#auction-invoices').html(data);
//Initiate Fancybox on links
$("a.example4").fancybox({
'opacity' : false,
'overlayShow' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'type' : 'iframe'
});
});
尽管如此,这是行不通的。有人有解决办法吗?
塔克斯
编辑:好的,找到解决方案:
$.post('php/common/auction_view/auction_invoices.php', function(data){
$('#auction-invoices').html(data);
$.getScript("fancybox/jquery.fancybox-1.3.4.js", function(){
$.fancybox.init();
$("a.example4").fancybox({
'transitionIn' : 'elastic',
'transitionOut' : 'elastic',
'overlayShow' : false,
'showCloseButton' : true,
'width' : 450,
'height' : 585,
'titleShow' : false,
'type' : 'iframe'
});
});
}))
Fancybox v1.3.x不支持动态添加的元素 我回答了一个类似的问题,它使用jQuery
.on()
方法将fancybox绑定到动态添加的元素
调整代码以匹配您的容器,如:
$("#auction-invoices").on("focusin", function(){...
这个答案对我没有帮助,太复杂了,但这是帮助我的解决方案(jquery 1.7.2和fancybox 1.3.4): 打开jquery.fancybox-1.3.4.js,像这样编辑第790行
$.fn.fancybox = function(options) {
if (!$(this).length) {
return this;
}
$(this)
.unbind('click.fb')
.live('click.fb', function(e) {
$(this).data('fancybox', $.extend({}, options, ($.metadata ? $(this).metadata() : {})))
e.preventDefault();
这个解决方案解决了我的问题,并且不需要更改任何其他内容,即使初始化仍然像默认设置一样
$(".trigger").fancybox();
它既简单又干净。希望对您有所帮助。您是否尝试过绑定此文件$(“a.example4”).bind(function(){$(this).fancybox({});});。这可能就是问题所在。我应该把它放到ajax调用中吗?
$(".trigger").fancybox();