Advertisement
Guest User

Untitled

a guest
May 27th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Find all YouTube videos
  2. jQuery(function($) {
  3.  
  4.     // The element that is fluid width
  5.     $fluidEl = $("body");
  6.  
  7. // Figure out and save aspect ratio for each video
  8. $allVideos.each(function() {
  9.  
  10.   $(this)
  11.     .data('aspectRatio', this.height / this.width)
  12.  
  13.     // and remove the hard coded width/height
  14.     .removeAttr('height')
  15.     .removeAttr('width');
  16.  
  17. });
  18.  
  19. // When the window is resized
  20. $(window).resize(function() {
  21.  
  22.   var newWidth = $fluidEl.width();
  23.  
  24.   // Resize all videos according to their own aspect ratio
  25.   $allVideos.each(function() {
  26.  
  27.     var $el = $(this);
  28.     $el
  29.       .width(newWidth)
  30.       .height(newWidth * $el.data('aspectRatio'));
  31.  
  32.   });
  33.  
  34. // Kick off one resize to fix all videos on page load
  35. }).resize();
  36.  
  37. );
  38. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement