2014-06-06 61 views
0

我想使用fancybox在彈出窗口中顯示原始圖像,但它似乎沒有工作。而是調整圖像和容器的寬度和高度。使用fancybox顯示原始圖像

這是我在做什麼:

$("a.fancybox").fancybox({ 
    padding : 0, 
    height : $(this).attr('data-height'), 
    width : $(this).attr('data-height'), 
    autoDimensions: false 
}); 

我的鏈接:

<a href="/system/creatives/images/000/000/008/original/new_creative_form.png?1402035793" data-width="1366" data-height="768" class="fancybox"> 
<img src="/system/creatives/images/000/000/008/thumb/new_creative_form.png?1402035793" class="img-responsive" alt="New creative form"> 
</a> 

任何想法,我應該怎麼辦呢?

+0

你有沒有試過不提供'width'和'height'參數? –

+0

@RoryMcCrossan呀還是它調整圖像大小。 –

回答

2

要見你只需要設置fitToViewfalse像圖像的原始尺寸:

$(".fancybox").fancybox({ 
    fitToView: false 
}); 

JSFIDDLE

在另一方面,如果你想操作傳遞的具體尺寸通過data屬性,然後使用beforeShow回撥如:

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

JSFIDDLE

注意我們仍然NEDD fitToView: false

重要

這是的fancybox v2.1.5,請確保您下載到更新的latest master

+0

要使用的fancybox v2.1.5 ..我們需要購買用於商業用途。對? –

+0

@SachinPrasad:所有fancyBox v2.x都需要商業網站的許可證,但您可以免費將其用於個人或非盈利網站。瞭解更多http://fancyapps.com/fancybox/#license – JFK