Created
September 13, 2017 16:56
-
-
Save Dexdot/3dd1b2f9733d7905e2b0bf67c4399d45 to your computer and use it in GitHub Desktop.
Youtube responsive
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
| // 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(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Изменить селектор в 4 строке (контейнер iframe'a)