0

I have a page that has a height of 320px, with a div hidden with jQuery. When the div shows, the height is 450px. I have put this in an iFrame, and would like to resize the iFrame when the hidden div is shown. I found this code from this question -

jQuery(function($){
  var lastHeight = 0, curHeight = 0, $frame = $('iframe:eq(0)');
  setInterval(function(){
    curHeight = $frame.contents().find('body').height();
    if ( curHeight != lastHeight ) {
      $frame.css('height', (lastHeight = curHeight) + 'px' );
    }
  },500);
});

And it works to increase the height of the frame, but I can't figure out how to get it to resize back to 320px when the div is hidden again. What would be the best way to modify this code so that the iFrame goes back to the original height of 320px?

Community
  • 1
  • 1
  • DOM elements have attributes associated with them including height. The JavaScript fragment appears to change the height of the iFrame. Prior to changing the height, capture the original height and save it in a variable. When you no longer wish the iFrame to be shown at the new height, execute code again to change the height of the iFrame to the height that it was previously. – Kolban Oct 29 '14 at 17:52
  • @Kolban Can you elaborate a little more on that? I feel like I understand what you mean, but can't figure out how to actually do it. –  Oct 29 '14 at 18:17

0 Answers0