Adjust jQuery Fancybox’ iframe height dynamically according to changed contents inside

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 accomplish this? Thanks!

newest questions tagged jquery – Stack Overflow

About Admin