Created
June 4, 2019 10:40
-
-
Save Patrick64/942daecfb34735ae0cc4474a421b3f93 to your computer and use it in GitHub Desktop.
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 resizeVideos() { | |
var $allVideos = $("iframe[src^='https://player.vimeo.com'], iframe[src^='https://www.youtube.com'], object, embed"); | |
$allVideos.each(function() { | |
$(this) | |
// jQuery .data does not work on object/embed elements | |
.attr('data-aspectRatio', this.height / this.width) | |
.removeAttr('height') | |
.removeAttr('width'); | |
}); | |
$(window).resize(function() { | |
$allVideos.each(function() { | |
var newWidth = $(this).parent().width(); | |
var $el = $(this); | |
$el | |
.width(newWidth) | |
.height(newWidth * $el.attr('data-aspectRatio')); | |
}); | |
}).resize(); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment