Created
November 30, 2021 15:10
-
-
Save feo52/b522e247dad3cfc6e268ab88e020f4a5 to your computer and use it in GitHub Desktop.
Embedding YouTube video fullscreen background
This file contains 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="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<title>youtube-fullscreen-background</title> | |
<style> | |
:root { | |
--youtube-aspect-ratio: (9 / 16); | |
} | |
.video-background-fixed-contain { | |
object-fit: contain; | |
position: fixed; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
width: 100%; | |
height: 100%; | |
z-index: -1; | |
pointer-events: none; | |
} | |
.video-background-fixed-cover { | |
object-fit: cover; | |
position: fixed; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
width: 100%; | |
height: 100%; | |
z-index: -1; | |
pointer-events: none; | |
} | |
.video-background-contain { | |
object-fit: contain; | |
object-position: center top; | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
width: 100%; | |
height: 100%; | |
z-index: -1; | |
pointer-events: none; | |
} | |
.video-background-cover { | |
object-fit: cover; | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
width: 100%; | |
height: 100%; | |
z-index: -1; | |
pointer-events: none; | |
} | |
.youtube-background-fixed-contain { | |
position: fixed; | |
top: 50%; | |
left: 50%; | |
width: min(100vw, calc(100vh / var(--youtube-aspect-ratio))); | |
height: min(100vh, calc(100vw * var(--youtube-aspect-ratio))); | |
transform: translate(-50%, -50%); | |
pointer-events: none; | |
z-index: -1; | |
} | |
.youtube-background-fixed-cover { | |
position: fixed; | |
top: 50%; | |
left: 50%; | |
width: max(100vw, calc(100vh / var(--youtube-aspect-ratio))); | |
height: max(100vh, calc(100vw * var(--youtube-aspect-ratio))); | |
transform: translate(-50%, -50%); | |
pointer-events: none; | |
z-index: -1; | |
} | |
.youtube-background-contain { | |
position: absolute; | |
top: 0%; | |
left: 50%; | |
width: min(100vw, calc(100vh / var(--youtube-aspect-ratio))); | |
height: min(100vh, calc(100vw * var(--youtube-aspect-ratio))); | |
transform: translate(-50%, 0%); | |
pointer-events: none; | |
z-index: -1; | |
} | |
.youtube-background-cover-container { | |
position: absolute; | |
top: 0; | |
left: 0; | |
right: 0; | |
bottom: 0; | |
z-index: -1; | |
overflow: hidden; | |
pointer-events: none; | |
} | |
.youtube-background-cover { | |
position: absolute; | |
top: 50%; | |
left: 50%; | |
width: max(100vw, calc(100vh / var(--youtube-aspect-ratio))); | |
height: max(100vh, calc(100vw * var(--youtube-aspect-ratio))); | |
transform: translate(-50%, -50%); | |
pointer-events: none; | |
z-index: -1; | |
} | |
</style> | |
<style> | |
.video-background-fixed-contain, | |
.video-background-fixed-cover, | |
.video-background-contain, | |
.video-background-cover, | |
.youtube-background-fixed-contain, | |
.youtube-background-fixed-cover, | |
.youtube-background-contain, | |
.youtube-background-cover { | |
opacity: .5; | |
} | |
#video-background-fixed-contain-switch:not(:checked) ~ .video-background-fixed-contain, | |
#video-background-fixed-cover-switch:not(:checked) ~ .video-background-fixed-cover, | |
#video-background-contain-switch:not(:checked) ~ .video-background-contain, | |
#video-background-cover-switch:not(:checked) ~ .video-background-cover, | |
#youtube-background-fixed-contain-switch:not(:checked) ~ .youtube-background-fixed-contain, | |
#youtube-background-fixed-cover-switch:not(:checked) ~ .youtube-background-fixed-cover, | |
#youtube-background-contain-switch:not(:checked) ~ .youtube-background-contain, | |
#youtube-background-cover-switch:not(:checked) ~ .youtube-background-cover-container { | |
display: none; | |
} | |
</style> | |
</head> | |
<body> | |
<br> | |
<input id ="video-background-fixed-contain-switch" type="checkbox"> | |
<label for="video-background-fixed-contain-switch">video-background-fixed-contain</label><br><br> | |
<input id ="video-background-fixed-cover-switch" type="checkbox"> | |
<label for="video-background-fixed-cover-switch">video-background-fixed-cover</label><br><br> | |
<input id ="video-background-contain-switch" type="checkbox"> | |
<label for="video-background-contain-switch">video-background-contain</label><br><br> | |
<input id ="video-background-cover-switch" type="checkbox"> | |
<label for="video-background-cover-switch">video-background-cover</label><br><br> | |
<input id ="youtube-background-fixed-contain-switch" type="checkbox"> | |
<label for="youtube-background-fixed-contain-switch">youtube-background-fixed-contain</label><br><br> | |
<input id ="youtube-background-fixed-cover-switch" type="checkbox" checked> | |
<label for="youtube-background-fixed-cover-switch">youtube-background-fixed-cover</label><br><br> | |
<input id ="youtube-background-contain-switch" type="checkbox"> | |
<label for="youtube-background-contain-switch">youtube-background-contain</label><br><br> | |
<input id ="youtube-background-cover-switch" type="checkbox"> | |
<label for="youtube-background-cover-switch">youtube-background-cover</label><br><br> | |
<video class="video-background-fixed-contain" src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4" playsinline autoplay loop muted></video> | |
<video class="video-background-fixed-cover" src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4" playsinline autoplay loop muted></video> | |
<video class="video-background-contain" src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4" playsinline autoplay loop muted></video> | |
<video class="video-background-cover" src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4" playsinline autoplay loop muted></video> | |
<iframe class="youtube-background-fixed-contain" src="https://www.youtube.com/embed/ZhJe6-XCjdI?playlist=ZhJe6-XCjdI&playsinline=1&autoplay=1&controls=0&disablekb=1&iv_load_policy=3&modestbranding=1&fs=0&loop=1&mute=1"></iframe> | |
<iframe class="youtube-background-fixed-cover" src="https://www.youtube.com/embed/ZhJe6-XCjdI?playlist=ZhJe6-XCjdI&playsinline=1&autoplay=1&controls=0&disablekb=1&iv_load_policy=3&modestbranding=1&fs=0&loop=1&mute=1"></iframe> | |
<iframe class="youtube-background-contain" src="https://www.youtube.com/embed/ZhJe6-XCjdI?playlist=ZhJe6-XCjdI&playsinline=1&autoplay=1&controls=0&disablekb=1&iv_load_policy=3&modestbranding=1&fs=0&loop=1&mute=1"></iframe> | |
<div class="youtube-background-cover-container"> | |
<iframe class="youtube-background-cover" src="https://www.youtube.com/embed/ZhJe6-XCjdI?playlist=ZhJe6-XCjdI&playsinline=1&autoplay=1&controls=0&disablekb=1&iv_load_policy=3&modestbranding=1&fs=0&loop=1&mute=1"></iframe> | |
</div> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
<br><br><br><br><br><br><br><br><br><br> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment