Skip to content

Instantly share code, notes, and snippets.

@nelsson
Created January 24, 2020 02:02
Show Gist options
  • Select an option

  • Save nelsson/57edf1831586319f5b22f51533ffdacd to your computer and use it in GitHub Desktop.

Select an option

Save nelsson/57edf1831586319f5b22f51533ffdacd to your computer and use it in GitHub Desktop.
function resizePlayer(iframes, ratio) {
if (!iframes[0]) return;
var win = $(".b1"),
width = win.width(),
playerWidth,
height = win.height(),
playerHeight,
ratio = ratio || 16/9;
$(iframes).each(function(){
var current = $(this);
if (width / ratio < height) {
playerWidth = Math.ceil(height * ratio);
current.width(playerWidth).height(height).css({
left: (width - playerWidth) / 2 + 10,
top: 12
});
} else {
playerHeight = Math.ceil(width / ratio);
current.width(width).height(playerHeight).css({
left: 0,
top: (height - playerHeight) / 2
});
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment