2016-06-13 171 views
0

我使用fancybox,我想设置一些图像的宽度和高度。 可以这样做吗?Fancybox设置一些图像的高度和宽度属性

所有的建议将是巨大的,并在此先感谢

+2

可能使用[使用fancybox集高度和宽度]重复(http://stackoverflow.com/questions/11306587/using-fancybox-set-height-and-width) – Mimouni

+0

它不是重复的,那另一个问题是关于iframe类型使用fancybox,这一个是关于图像类型。 iframe类型的解决方案对我无效。 – Vero

回答

0

当试图设置宽度和高度为的fancybox的“图像”类型,这个工作对我来说:

jQuery(".fancybox").fancybox({ 
arrows : true, 
autoSize: false, 
fitToView: false, 
afterLoad: function(){ 
    this.width = 960; 
    this.height = 540; 
    } 
} 
}); 

如果你改变960 540为你需要的任何值,或者你也可以在函数中做一个javascript计算。如果您想为特定图片运行代码,则可以检查ID或当前元素的其他属性。例如,如果这是你的HTML:

<div class="photo-block fancybox" id="image1" data-fancybox-group="group" href="/image.jpg" title="Image description to show"> 
<div class="photo-block-img"><img src="/image.jpg"/></div> 
<div class="photo-block-text">Some text that shows in here</div></div><div class="photo-block fancybox" id="image2" data-fancybox-group="group" href="/image.jpg" title="Image description to show"> 
<div class="photo-block-img"><img src="/image.jpg"/></div> 
<div class="photo-block-text">Some text that shows in here</div> 

然后,你可以执行如下命令仅此申请ID“图像2”,后负荷函数内部:

if($(this.element).attr('id') == 'image2'){ 
    this.width=960; 
    this.height=540; 
} 

我不得不使用“afterLoad”而不是“beforeLoad”,正如我在“iframe”类型的答案中看到的那样。 beforeLoad对图像类型没有任何影响,但是在负载工作之后。

相关问题