Background Video
Overlay on background video
HTML
<div class="common">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis atque sapiente laudantium corrupti quae neque laboriosam placeat voluptatem eaque? Voluptatibus rerum veniam fugit perferendis nam porro nihil placeat architecto nulla!
</div>
CSS
.common {
height: 30% !important;
width: 100% !important;
background-color: pink;
opacity: 0.3;
z-index: 0;
}
JavaScript
/**
* @preserve Copyright 2011 Syd Lawrence ( www.sydlawrence.com ).
* Version: 0.2
*
* Licensed under MIT and GPLv2.
*
* Usage: $('body').videoBG(options);
*
*/
(function( $ ){
$.fn.videoBG = function( selector, options ) {
if (options === undefined) {
options = {};
}
if (typeof selector === "object") {
options = $.extend({}, $.fn.videoBG.defaults, selector);
}
else if (!selector) {
options = $.fn.videoBG.defaults;
}
else {
return $(selector).videoBG(options);
}
var container = $(this);
// check if elements available otherwise it will cause issues
if (!container.length) {
return;
}
// container to be at least relative
if (container.css('position') == 'static' || !container.css('position')) {
container.css('position','relative');
}
// we need a width
if (options.width === 0) {
options.width = container.width();
}
// we need a height
if (options.height === 0) {
options.height = container.height();
}
// get the wrapper
var wrap = $.fn.videoBG.wrapper();
wrap.height(options.height)
.width(options.width);
// if is a text replacement
if (options.textReplacement) {
// force sizes
options.scale = true;
// set sizes and forcing text out
container.width(options.width)
.height(options.height)
.css('text-indent','-9999px');
}
else {
// set the wrapper above the video
wrap.css('z-index',options.zIndex+1);
}
// move the contents into the wrapper
wrap.html(container.clone(true));
// get the video
var video = $.fn.videoBG.video(options);
// if we are forcing width / height
if (options.scale) {
// overlay wrapper
wrap.height(options.height)
.width(options.width);
// video
video.height(options.height)
.width(options.width);
}
// add it all to the container
...