问题
I'm using bootstrap and I want to set youtube video on background
I found this. How could I change this code to use video from youtube? replacing with doesn't work
@import url('http://fonts.googleapis.com/css?family=Oswald');
body {
margin: 0;
padding: 0;
background-attachment: fixed;
background-size: cover;
}
#video-background {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
}
<video autoplay="" loop="" class="fillWidth fadeIn animated" poster="https://s3-us-west-2.amazonaws.com/coverr/poster/Traffic-blurred2.jpg" id="video-background">
<source src="https://s3-us-west-2.amazonaws.com/coverr/mp4/Traffic-blurred2.mp4" type="video/mp4">
</video>
回答1:
I found good solution here.
.video-background {
background: #000;
position: fixed;
top: 0; right: 0; bottom: 0; left: 0;
z-index: -99;
}
.video-foreground,
.video-background iframe {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
pointer-events: none;
}
回答2:
OH HI EVERYONE, here is a reusable simple jQuery plugin I made based on YouTube Embed API. It's also super simple to use. You can see it in action here.
<div id="ytbg" data-youtube="https://www.youtube.com/watch?v=eEpEeyqGlxA"></div>
<script type="text/javascript">
jQuery(document).ready(function() {
$('[data-youtube]').youtube_background();
});
</script>
Code on GitHub
回答3:
In your body
just add those lines.Change the id number.
<div style="position: fixed; z-index: -99; width: 100%; height: 100%">
<iframe frameborder="0" height="100%" width="100%"
src="https://youtube.com/embed/ID?autoplay=1&controls=0&showinfo=0&autohide=1">
</iframe>
</div>
回答4:
Using Youtube API + CSS, we can build full screen youtube video background.
HTML Markup:
<div class="page">
<div class="video-bg">
<div id="videoPlayer" data-videoid="b0r_dH7jfOM"></div>
</div>
<div class="content">
<h1>Video Player background</h1>
<h3>Full screen youtube video player in background.</h3>
</div>
</div>
CSS:
.page {
position: relative;
overflow: hidden;
}
.page .video-bg {
width: 100%;
height: 0;
padding-bottom: 56.25%;/* Aspect ratio */
position: absolute;
}
.page .video-bg iframe {
border: 0;
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.page .content {
position: relative;
z-index: 1;
}
Add Youtube API: https://www.youtube.com/iframe_api
JS:
jQuery(function () {
// Youtube player
window.videoPlayer;
window.onYouTubeIframeAPIReady = function () {
var videoPlayerId = $('#videoPlayer').attr('data-videoid');
window.videoPlayer = new YT.Player('videoPlayer', {
height: '1080',
width: '1920',
videoId: videoPlayerId,
playerVars: {
'controls': 0,
'autoplay': 1,
'mute': 1,
'loop': 1,
'showinfo': 0,
'modestbranding': 1
},
events: {
'onReady': onVideoPlayerReady,
'onStateChange': onVideoPlayerReady
}
});
}
function onVideoPlayerReady(event) {
videoPlayer.playVideo();
}
});
回答5:
You can use embeded videos from youtube and just put id="video-background" and remove height/width
<iframe id="video-background" src="https://www.youtube.com/embed/BrCKvKXvN2c?list=RDgfwMBzGA_Jo" frameborder="0" allowfullscreen></iframe>
Explained HERE
来源:https://stackoverflow.com/questions/42055200/set-youtube-video-on-background