Fancybox 2高度不起作用

问题描述 投票:12回答:3

我正在尝试从我的fancybox中获取两个不同的高度,具体取决于客户端单击的链接,但是出于某种原因,该高度一直保持在100%。不会达到我想要的高度

这是我的代码

$('.fancyboxhd').fancybox({
  width: 1287,
  height: 720
});
$('.fancyboxsd').fancybox({
  width: 640,
  height: 360,
});

这是iFrame内容

jquery fancybox
3个回答
57
投票

请参见下面的编辑以获取改善的答案)] >>>

对于iframe内容,您的html应该看起来像

<a class="fancyboxhd fancybox.iframe" href="hdfile.html">hd</a>
<a class="fancyboxsd fancybox.iframe" href="sdfile.html">sd</a>

然后将这两个选项添加到脚本中

fitToView   : false,
autoSize    : false

所以您的脚本应该看起来像

$(document).ready(function(){
 $('.fancyboxhd').fancybox({
   width : 1287,
   height : 720,
   fitToView : false,
   autoSize : false
 });
 $('.fancyboxsd').fancybox({
   width: 640,
   height: 360,
   fitToView : false,
   autoSize : false
 });
});

###编辑###

:( 2013年9月5日)

可以使用锚中的(HTML5)data-*属性和两个选项相同的class来改进和简化代码:>

HTML

<a class="fancybox fancybox.iframe" data-width="1287" data-height="720" href="hdfile.html">HD</a>
<a class="fancybox fancybox.iframe" data-width="640"  data-height="360" href="sdfile.html">SD</a>

JS

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

请参见JSFIDDLE

NOTE

:在进行此编辑时,演示使用了fancybox v2.1.5。

对于v2.1.5,您可以通过使用html元素的ID来使用。

<a id="item1" class="fancybox" href="http://fiddle.jshell.net/YtwCt/show/">Open 500x200</a>

<br />

<a id="item2" class="fancybox" href="http://fiddle.jshell.net/YtwCt/show/">Open 200x500</a>

<div id="test" style="display:none">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pulvinar, nulla eu interdum posuere, nisi mauris cursus nisi, nec faucibus nibh urna nec turpis.


$(".fancybox-wrap").draggable();
$(".fancybox")
    .attr('rel', 'gallery')
    .fancybox({
        type: 'iframe',
        autoSize : false,
        beforeLoad : function() {         
            if ($(this.element).attr('id') == 'item1') {
                this.width  = 500;
                this.height = 200;
            }
        else {
                this.width  = 200;
                this.height = 500;
            }
        }
    });

设置autoScale:false,

$('.fancyboxhd').fancybox({
  width: 1287,
  height: 720,
  autoScale : false,
});

0
投票

对于v2.1.5,您可以通过使用html元素的ID来使用。

<a id="item1" class="fancybox" href="http://fiddle.jshell.net/YtwCt/show/">Open 500x200</a>

<br />

<a id="item2" class="fancybox" href="http://fiddle.jshell.net/YtwCt/show/">Open 200x500</a>

<div id="test" style="display:none">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce pulvinar, nulla eu interdum posuere, nisi mauris cursus nisi, nec faucibus nibh urna nec turpis.


$(".fancybox-wrap").draggable();
$(".fancybox")
    .attr('rel', 'gallery')
    .fancybox({
        type: 'iframe',
        autoSize : false,
        beforeLoad : function() {         
            if ($(this.element).attr('id') == 'item1') {
                this.width  = 500;
                this.height = 200;
            }
        else {
                this.width  = 200;
                this.height = 500;
            }
        }
    });

0
投票

设置autoScale:false,

© www.soinside.com 2019 - 2024. All rights reserved.