【问题标题】:Adjust jQuery Fancybox' iframe height dynamically according to changed contents inside根据内部更改的内容动态调整 jQuery Fancybox 的 iframe 高度
【发布时间】:2011-11-17 20:08:08
【问题描述】:

我正在使用 jQuery Fancybox 在模式窗口中显示表单。我正在使用以下代码:

$("a.iframe").fancybox({
'padding': 0,
'width': 650,
'showCloseButton': false,
'hideOnContentClick': false,
'transitionIn': 'elastic',
'transitionOut': 'elastic',
'onComplete': function () {
  $('#fancybox-frame').load(function () {
    $('#fancybox-content').height($(this).contents().find('body').height() + 20);
  });
}
});

通过附加的 onComplete 函数,我可以根据内部内容的高度调整 iframe 的高度。

但是,我在 iframe 中使用 jQuery 的 .hide() 隐藏了一些元素。每当我想 .show() 这些元素时,iframe 本身不会随着现在可见元素的额外高度一起调整大小。

我怎样才能做到这一点?谢谢!

【问题讨论】:

标签: javascript jquery iframe height fancybox


【解决方案1】:

将以下函数放到页面中

$.fn.ResizeFancy = function(){
   $('#fancybox-content').height($('#fancybox-frame').contents().find('body').height() + 20);
};

之后,将这个函数触发到你的 showHide 函数。例如;

function yourShowHideFn(){
    //bla bla bla

    $.fn.ResizeFancy();
}

【讨论】:

    猜你喜欢
    • 2012-05-21
    • 2012-07-29
    • 2015-04-14
    • 2012-08-03
    • 2010-12-18
    • 2012-01-06
    • 2012-09-28
    • 2011-11-14
    • 1970-01-01
    相关资源
    最近更新 更多