【发布时间】:2012-02-01 16:02:27
【问题描述】:
这就是他们在工作中定义灯箱的方式
$(".lightbox873x560").colorbox({width:"845", height:"555", resize:false, iframe:true, scrolling:"no", opacity:"0.65"});
$(".lightboxGallery").colorbox({width:"845", height:"555", resize:false, iframe:true, scrolling:"no", opacity:"0.65"});
等等。
这就是我的建议
$(".lightboxCustom").colorbox({
width: $(this).attr('lWidth'), height: $(this).attr('lHeight'), resize:false, iframe:true, scrolling:"no", opacity:"0.65"
});
这样属性 lWidth,lHeight 将决定颜色框的尺寸,
问题是主体上的加载的内容将具有另一个预定义的类,它将修复灯箱内容的宽度..
那么我怎样才能删除它?
我看到 colorbox 得到了这个额外的参数:
$(".lightboxCustom").colorbox({
width: $(this).attr('lWidth'), height: $(this).attr('lHeight'), resize:false, iframe:true, scrolling:"no", opacity:"0.65",
onOpen:function(){ alert('onOpen: colorbox is about to open'); },
onLoad:function(){ alert('onLoad: colorbox has started to load the targeted content'); },
onComplete:function(){ alert('onComplete: colorbox has displayed the loaded content'); }
});
那么用什么方法呢?完成,对吧?我怎样才能找到/选择身体??
尝试:
onComplete:function(){
console.log( $('#cboxIframe').length );
console.log( $('#colorbox #cboxWrapper #cboxLoadedContent iframe').length );
}
但两者都记录 0 并且是具有 iframe 的类..
编辑
目前这是我最近的一次:
$(".lightboxCustom").each(function(){
$(this).colorbox({width: $(this).attr('lWidth'), height: $(this).attr('lHeight'), resize:false, iframe:true, scrolling:"no", opacity:"0.65",fastIframe:false,
onComplete:function(){
$(document).bind('cbox_complete',function(){
var iframe = $('#colorbox div#cboxWrapper div div#cboxContent div#cboxLoadedContent iframe#cboxIframe');
var body = iframe.contents().find('body');
console.log(iframe.length); /// ---> 1!!
console.log(body.lenght); /// ---> 1 :(
/*But the problem is that this is empty*/
alert(body.attr('class')); /*when its not*/
})
}
});
});
【问题讨论】:
-
$(".lightboxCustom") 链接的域是否与您的站点域不同?
标签: javascript jquery iframe lightbox colorbox