Last active
January 27, 2023 12:33
-
-
Save negatronGister/8789622 to your computer and use it in GitHub Desktop.
full screen video background
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
| <!doctype html> | |
| <html lang=en> | |
| <head> | |
| <title>full screen video</title> | |
| <style> | |
| html, body { | |
| width: 100%; | |
| height: 100%; | |
| padding: 0; | |
| margin: 0; | |
| } | |
| .background { | |
| width: 100%; | |
| height: 100%; | |
| position: fixed; | |
| } | |
| .backgroundVideo { | |
| width: 100%; | |
| height: 100%; | |
| position: relative; | |
| overflow: hidden; | |
| } | |
| .backgroundVideo video { | |
| position: absolute; | |
| display: inline-block; | |
| } | |
| .player { | |
| width: 100%; | |
| height: 100%; | |
| } | |
| </style> | |
| <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" ></script> | |
| </head> | |
| <body> | |
| <div class="background"> | |
| <div class="backgroundVideo"> | |
| <div class="player"> | |
| <video autoplay loop poster="/video/videoBackground.jpg"> | |
| <source src="video.mp4" type="video/mp4"> | |
| </video> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| var HEIGHT = $(window).height(); | |
| var WIDTH = $(window).width(); | |
| var $player = $('.player'); | |
| var $video = $player.children('video'); | |
| var videRatio = 16 / 9; | |
| function resizeVideo () { | |
| var playerHeight = HEIGHT; | |
| var playerWidth = WIDTH; | |
| var containerRatio = WIDTH / HEIGHT; | |
| var playerCSS, videoCSS; | |
| if (containerRatio < videoRatio) { | |
| playerCSS = { | |
| width: HEIGHT * videoRatio, | |
| height: HEIGHT | |
| } | |
| videoCSS = { | |
| top: 0, | |
| left: -(HEIGHT * videoRatio - WIDTH) / 2, | |
| height: HEIGHT | |
| } | |
| } else { | |
| playerCSS = { | |
| width: WIDTH, | |
| height: WIDTH * videoRatio | |
| } | |
| videoCSS = { | |
| top: -(WIDTH / videoRatio - HEIGHT) / 2, | |
| left: 0, | |
| height: WIDTH / videoRatio | |
| } | |
| } | |
| $player.css(playerCSS).css({top:0}); | |
| $video.css(videoCSS); | |
| } | |
| resizeVideo(); | |
| $(vid).on('play', function() { | |
| resizeVideo(); | |
| //hide loader | |
| }); | |
| $(window).resize(function(event) { | |
| HEIGHT = $(window).height(); | |
| WIDTH = $(window).width(); | |
| resizeVideo(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment