2016-06-13 111 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對圖像類型沒有任何影響,但是在負載工作之後。

相關問題