Skip to content

Instantly share code, notes, and snippets.

@ozamancse
Created March 31, 2020 17:57
Show Gist options
  • Select an option

  • Save ozamancse/2e6579b3a00ead400f91fc95431cc47e to your computer and use it in GitHub Desktop.

Select an option

Save ozamancse/2e6579b3a00ead400f91fc95431cc47e to your computer and use it in GitHub Desktop.
(function ($) {
"use strict";
jQuery(document).ready(function ($) {
function adjustIframes() {
$('iframe').each(function() {
var $this = $(this),
proportion = $this.data( 'proportion' ),
w = $this.attr('width'),
actual_w = $this.width();
if ( ! proportion ) {
proportion = $this.attr('height') / w;
$this.data( 'proportion', proportion );
}
if ( actual_w !== w ) {
$this.css( 'height', Math.round( actual_w * proportion ) + 'px' );
}
});
}
$(window).on('resize load',adjustIframes);
});
}(jQuery));
@ozamancse
Copy link
Author

Use below CSS with this JS file
iframe {
max-width: 100%;
width: 100%;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment