javascript - Adjust jQuery Fancybox' iframe height dynamically according to changed contents inside - Stack Overflow

I'm using jQuery Fancybox to display forms in a modal window. I'm using the following code:$(

I'm using jQuery Fancybox to display forms in a modal window. I'm using the following code:

$("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);
  });
}
});

With the additional onComplete function, I'm able to adjust the height of the iframe accordingly to the height of the contents inside.

However, I've hidden a few elements with jQuery's .hide() inside the iframe. Whenever I want to .show() these elements, the iframe itself doesn't resize along with the extra height of the now visible elements.

How can I acplish this? Thanks!

I'm using jQuery Fancybox to display forms in a modal window. I'm using the following code:

$("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);
  });
}
});

With the additional onComplete function, I'm able to adjust the height of the iframe accordingly to the height of the contents inside.

However, I've hidden a few elements with jQuery's .hide() inside the iframe. Whenever I want to .show() these elements, the iframe itself doesn't resize along with the extra height of the now visible elements.

How can I acplish this? Thanks!

Share Improve this question asked Sep 15, 2011 at 12:13 Martijn van TurnhoutMartijn van Turnhout 2711 gold badge6 silver badges20 bronze badges 1
  • 1 I think this trend has the answer to your request: Problem Adjusting Fancybox Iframe Overlay Width and Height – JAY Commented Dec 16, 2011 at 8:12
Add a ment  | 

1 Answer 1

Reset to default 2

Put the following function to the page

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

After, trigger this function to your showHide function. For example;

function yourShowHideFn(){
    //bla bla bla

    $.fn.ResizeFancy();
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745462211a4628758.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信