Last active
March 4, 2020 06:26
-
-
Save klx-hansspiess/64eed56ac1e63c82dde0 to your computer and use it in GitHub Desktop.
make vimeo embeds responsive
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
// Responsive Vimeo Embed: http://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php | |
var $allVideos = $("iframe[src^='//player.vimeo.com']"); | |
$allVideos.each(function() { | |
$(this) | |
.data('aspectRatio', this.height / this.width) | |
.removeAttr('height') | |
.removeAttr('width'); | |
}); | |
$(window).resize(function() { | |
$allVideos.each(function() { | |
var $el = $(this); | |
$el.width( $(this).parent().width() ).height( $(this).parent().width() * $el.data('aspectRatio')); | |
}); | |
}).resize(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment