Skip to content

Instantly share code, notes, and snippets.

@fatihgvn
Created September 18, 2019 10:49
Show Gist options
  • Save fatihgvn/a5b561024e0eaf5853968b8270d26443 to your computer and use it in GitHub Desktop.
Save fatihgvn/a5b561024e0eaf5853968b8270d26443 to your computer and use it in GitHub Desktop.
iframe auto resize from width
$(function() {
// auto size iframe
$('iframe[data-size]').each(function () {
var frame = $(this);
var size = frame.data('size').split('x');
var rate = size[0]/size[1];
frame.width(size[0]);
frame.height(frame.width()/rate);
this.contentWindow.addEventListener('resize', function(){
frame.height(frame.width()/rate);
});
});
});
<iframe src="http://adOrSiteView.com/example" scrolling="no" data-size="728x90"></iframe>
iframe{
border: none;
overflow: hidden;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment