Created
April 6, 2016 14:57
-
-
Save bobvanluijt/2ca2e69aaa1703002ec733aa80bd4cbb to your computer and use it in GitHub Desktop.
Center a video element in full screen mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set the video sizes | |
*/ | |
var videoWith = 1280, | |
videoHeight = 720; | |
/** | |
* The magic | |
*/ | |
var videoRatio = videoHeight / videoWith, | |
videoNewHeight = $(window).width() * videoRatio; | |
if(videoNewHeight > $(window).height()){ | |
$('video') | |
.css({ | |
width : $(window).width() * 1.05, | |
height : ($(window).width() * 1.05) * videoRatio, | |
marginTop : (0 - ((($('video').height() - ($(window).height() * 1.05) ) / 2) * 1.05)) + 'px', | |
marginLeft: 0 | |
}) | |
} else { | |
$('video') | |
.css({ | |
width : '', | |
height : $(window).height() * 1.05, | |
marginTop : 0, | |
marginLeft: (0 - ((($('video').width() - ($(window).width() * 1.05) ) / 2) * 1.05)) + 'px' | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment