2013-07-10 53 views
2

我想知道是否可以在fancybox圖片上設置自定義寬度和高度?fancybox圖片上的自定義寬度和高度

作爲一個標準,fancybox的寬度和高度相對於圖像的寬度和高度發生了變化,但是我想在所有圖像上都是800寬度和600高度。

我想創建一些與Facebook上的圖像框熟悉的東西,您可以在左側看到圖像,並在右側顯示說明和評論。

可能是巨大的,如果有人可以幫助我這個... :)

  • TheYaXxE

回答

15

更簡單的方法是改變兩者的大小,打開的fancybox圖像和的fancybox使用beforeShow回調父容器,如:

$(".fancybox").fancybox({ 
    fitToView: false, // avoids scaling the image to fit in the viewport 
    beforeShow: function() { 
     // set size to (fancybox) img 
     $(".fancybox-image").css({ 
      "width": 800, 
      "height": 600 
     }); 
     // set size for parent container 
     this.width = 800; 
     this.height = 600; 
    } 
}); 

JSFIDDLE

注意:這是對的fancybox版本2.x +


編輯(2014年4月):

當前版本的fancybox的(v2.1.5今天),這是不需要將css規則應用於.fancybox-image選擇器,因爲圖像現在設置爲響應式(max-width: 100%;)。 this.width獨自01​​會做的伎倆

$(".fancybox").fancybox({ 
    fitToView: false, 
    beforeShow: function() { 
     this.width = 800; 
     this.height = 600; 
    } 
}); 

見分叉JSFIDDLE

+1

「編輯(2014年4月)」 版本我 –

+0

我用得太....感謝。 –

+0

謝謝bruhhh! –

相關問題