I'm trying to get a YouTube video to load and span the entire with and height of a div (hero__container--teaser
). I've managed to get the video to load but unsure on how I can make it the div's background?
Here's my hero.js:
// Load IFrame Player API
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// Creating iframe
var player;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: 'jagIsKF8oVA',
playerVars: {'autoplay': 1, 'controls': 0, 'mute' : 1, 'loop': 1, 'rel': 0 },
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
}
// Calls function
function onPlayerReady(event) {
event.target.playVideo();
}
var done = false;
function onPlayerStateChange(event) {
// if (event.data == YT.PlayerState.PLAYING && !done) {
// setTimeout(stopVideo, 6000);
// done = true;
// }
}
function stopVideo() {
// player.stopVideo();
}
<div id="player"></div>
<section id="videoHero" class="hero hero--video">
<!-- Where I want video to load -->
<div class="player hero__container--teaser">
</div>
</section>
Idea's?
ANSWER: https://codepen.io/GAUTAMRAJU15/pen/wENdzg This link contains Answer . IT WRAPS DIV AROUND IFRAME