Skip to content

Instantly share code, notes, and snippets.

@Dexdot
Created September 13, 2017 16:56
Show Gist options
  • Select an option

  • Save Dexdot/3dd1b2f9733d7905e2b0bf67c4399d45 to your computer and use it in GitHub Desktop.

Select an option

Save Dexdot/3dd1b2f9733d7905e2b0bf67c4399d45 to your computer and use it in GitHub Desktop.
Youtube responsive
// Youtube fluid
// Find all YouTube videos
var $allVideos = $("iframe[src^='//www.youtube.com']"),
$fluidEl = $(".process__video"); // video-container (change it)
$allVideos.each(function() {
$(this)
.data('aspectRatio', this.height / this.width)
.removeAttr('height')
.removeAttr('width');
});
$(window).resize(function() {
var newWidth = $fluidEl.width();
$allVideos.each(function() {
var $el = $(this);
$el
.width(newWidth)
.height(newWidth * $el.data('aspectRatio'));
});
}).resize();
@Dexdot

Dexdot commented Sep 13, 2017

Copy link
Copy Markdown
Author

Изменить селектор в 4 строке (контейнер iframe'a)

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