问题
I've been trying to set a video as background, I have the flv-file and youtube-link. Putting it on my website isn't that difficult with html5 video-tag or jquery but I can't find how I can put it on my website but not auto starting. I have a semi-transparent rectangle where the text will come over. So my idea was creating a button or link to let the text and rectangle dissappear and letting the video play.
Does anyone knows a good plugin or script to do this or can someone bump into the right direction.
greetz
回答1:
You can do this with native browser html5 video player too which will be much faster, no need to use a plugin. Try this:
Here is working jsFiddle example.
jQuery:
$(document).ready(function() {
var windowH = $(window).height();
$('#main_container, #overlay').height(windowH);
$(window).resize(function () {
var windowH = $(window).height();
$('#main_container, #overlay').height(windowH);
});
});
css:
body { background-color: #000000; font-family: Arial; font-size: 12px;
color: #000; margin: 0; padding: 0; overflow: hidden; }
#main_container { float: left; position: relative; width: 100%; height: 100%;
background-color: #000000; }
#video { position: absolute; left: 0px; top: 0px; min-height: 100%;
min-width: 100%; z-index: 9997; }
#overlay { position: absolute; left: 0px; top: 0px; height: 100%; width: 100%;
z-index: 9998; }
html:
<div id="main_container">
<div id="overlay"></div>
<video id="video" width="" height="" controls="controls" loop="loop" autoplay="">
<source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/mp4" />
<source src="http://www.w3schools.com/html/mov_bbb.ogg" type="video/ogg" />
Your browser does not support the video tag.
</video>
</div>
Note: Used overlay div for deactivating controls and you can use whatever content on your video, like in jsFiddle example.
回答2:
If you want a script, you can try: https://github.com/sydlawrence/jquery.videoBG
In the documentation here: http://syddev.com/jquery.videoBG/index.html#documentation, there seems to be an auto play option with a Boolean parameter...so I'm guessing just set it to false
autoplay bool
来源:https://stackoverflow.com/questions/11903924/video-as-background-on-a-website-playing-on-command