Skip to content

Instantly share code, notes, and snippets.

@dnieh
Last active March 29, 2016 07:28
Show Gist options
  • Save dnieh/cdee840d724d5371814f to your computer and use it in GitHub Desktop.
Save dnieh/cdee840d724d5371814f to your computer and use it in GitHub Desktop.
responsive full screen video on desktop and mobile (app.js)
'use strict';
$(function() {
var app = (function() {
var $videoContainer = $('.video-container');
var $video = $('.video');
var ratioWidth = 16;
var ratioHeight = 9;
var ratioCheck = function() {
var ratio = $(window).height() / $(window).width();
if (ratio > 0.562) {
handleHeightCentricDisplay();
} else if (ratio < 0.562) {
handleWidthCentricDisplay();
}
};
var handleHeightCentricDisplay = function() {
var windowHeight = $(window).height();
var newVideoWidth = ratioWidth * windowHeight / ratioHeight;
$video.css({
height: windowHeight,
width: newVideoWidth,
left: (newVideoWidth - $(window).width()) / 2 * -1
});
$videoContainer.css('height', windowHeight);
};
var handleWidthCentricDisplay = function() {
var windowWidth = $(window).width();
var windowHeight = $(window).height();
var newVideoHeight = ratioHeight * windowWidth / ratioWidth;
$video.css({
height: newVideoHeight,
width: windowWidth,
left: 0,
top: (newVideoHeight - windowHeight) / 2 * -1
});
$videoContainer.css('height', windowHeight);
};
var listenForVideoResize = function() {
$(window).on('resize', function() {
ratioCheck();
});
};
var init = function() {
ratioCheck();
listenForVideoResize();
};
return {
init: init
};
})();
app.init();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment