Skip to content

Instantly share code, notes, and snippets.

@pyroflies
Created March 26, 2018 19:17
Show Gist options
  • Save pyroflies/f9263123adf9071fcf99b855af0f22a0 to your computer and use it in GitHub Desktop.
Save pyroflies/f9263123adf9071fcf99b855af0f22a0 to your computer and use it in GitHub Desktop.
Full Screen Video Resize Fill
var video = $('#video');
var resizeVideo = function() {
var w = $("body").prop("clientWidth");
var h = window.innerHeight;
var ratio = 0.5625; // 720x1280 or 1080x1920
if (h/w > ratio) {
var width = ((h/720) / (w/1280)) * 100;
video.css('width', width + '%');
video.css('height', '100vh');
} else {
var height = ((w/1280) / (h/720)) * 100;
video.css('width', '100%');
video.css('height', height + 'vh');
}
}
$(window).resize(function() {
resizeVideo();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment