$(document).ready(function() { ratioVideoFrame(); $(window).on('resize', function() { setTimeout(function() { ratioVideoFrame(); }, 300); }); function ratioVideoFrame() { $('div.video-wrapper .video-item').each(function() { var video = $(this).find('iframe'), videoHeight = video.outerHeight(), videoWidth = video.outerWidth(), aspectRatio = (videoHeight / videoWidth) * 100, newWidth = videoHeight * aspectRatio, halfNewWidth = newWidth / 2; video.css({ "width": newWidth + "px", "left": "50%", "margin-left": "-" + halfNewWidth + "px" }); }); } });