Last active
December 15, 2015 06:39
-
-
Save mandelbro/5218120 to your computer and use it in GitHub Desktop.
When you set an iFrame to max-width 100%, it can't adjust it's own height. That is because iFrames are stupid, this plugin is like a 4 year education to an iFrame, which the iFrame will squander anyway.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
var methods = { | |
adjustHeight : function(ratio, width) { | |
if(width == currentWidth) return; | |
currentWidth = width; | |
this.height(width/ratio); | |
} | |
}, | |
currentWidth; | |
// allow iFrames to have a 'max-width' | |
$.fn.flexiFrame = function() { | |
// first set a max-width of 100% if it doesn't already have that | |
this.css('max-width', ''); | |
var self = this, | |
width = this.width(), | |
ratio = width / this.height(); | |
currentWidth = width; | |
setTimeout(function() { | |
self.css('max-width', '100%'); | |
window.setInterval(function() { | |
methods.adjustHeight.apply(self, [ratio, self.width()]); | |
}, 100); | |
}, 10); | |
}; | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment