Skip to content

Instantly share code, notes, and snippets.

@Adoonq
Last active November 2, 2018 11:46
Show Gist options
  • Save Adoonq/f0027e198340ed45b6ae87f04dfbcefa to your computer and use it in GitHub Desktop.
Save Adoonq/f0027e198340ed45b6ae87f04dfbcefa to your computer and use it in GitHub Desktop.
YouTube VideoBackground
iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
@media (min-aspect-ratio: 16/9) {height: 300%; top: -100%}
@media (max-aspect-ratio: 16/9) {width: 300%; left: -100%}
}
// <script src="https://www.youtube.com/iframe_api"></script>
var videoId = 'leSaAaWrkK0',
muted = 0;
if (videoId) {
$('[data-youtube]').html('<div id="player"></div>');
function onYouTubeIframeAPIReady() {
var player = new YT.Player('player', {
videoId: videoId,
events: {'onReady': onPlayerReady},
playerVars: {controls: 0, showinfo: 0, rel: 0, autoplay: 1, loop: 1, iv_load_policy: 3, mute: muted, playlist: videoId}
});
}
function onPlayerReady(event) {event.target.playVideo()}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment