Skip to content

Instantly share code, notes, and snippets.

@klx-hansspiess
Last active March 4, 2020 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klx-hansspiess/64eed56ac1e63c82dde0 to your computer and use it in GitHub Desktop.
Save klx-hansspiess/64eed56ac1e63c82dde0 to your computer and use it in GitHub Desktop.
make vimeo embeds responsive
// 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