Video as background on a website playing on command

不问归期 提交于 2019-12-05 17:38:01
Barlas Apaydin

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!