Created
December 8, 2014 19:13
-
-
Save kohlmannj/aef0b2df698727b0ea48 to your computer and use it in GitHub Desktop.
jQuery Plugin: iframe Scaler (transforms iframes to fit inside their containing elements)
This file contains 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($) { | |
$.fn.iframeScale = function() { | |
this.each(function() { | |
var $iframe = $(this).find("iframe"); | |
var scaleFactor = $(this).width() / $iframe.width(); | |
$iframe.css({ | |
webkitTransform: "scale(" + scaleFactor + ")", | |
mozTransform: "scale(" + scaleFactor + ")", | |
msTransform: "scale(" + scaleFactor + ")", | |
transform: "scale(" + scaleFactor + ")" | |
}); | |
}); | |
return this; | |
}; | |
}( jQuery )); | |
// Sample Usage: | |
// | |
// 1. Select containing elements and call the plugin on page load: | |
// $(".prototype").iframeScale(); | |
// | |
// 2. Call the plugin on window resize to support fluid width / proportional height containers: | |
// | |
// $(window).on("resize", function() { | |
// $(".prototype").iframeScale(); | |
// }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment