/** * @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 container.html(wrap); container.append(video); return video.find("video")[0]; }; // set to fullscreen $.fn.videoBG.setFullscreen = function($el) { var windowWidth = $(window).width(), windowHeight = $(window).height(); $el.css('min-height',0).css('min-width',0); $el.parent().width(windowWidth).height(windowHeight); // if by width var shift = 0; if (windowWidth / windowHeight > $el.aspectRatio) { $el.width(windowWidth).height('auto'); // shift the element up var height = $el.height(); shift = (height - windowHeight) / 2; if (shift < 0) { shift = 0; } $el.css("top",-shift); } else { $el.width('auto').height(windowHeight); // shift the element left var width = $el.width(); shift = (width - windowWidth) / 2; if (shift < 0) { shift = 0; } $el.css("left",-shift); // this is a hack mainly due to the iphone if (shift === 0) { var t = setTimeout(function() { $.fn.videoBG.setFullscreen($el); },500); } } $('body > .videoBG_wrapper').width(windowWidth).height(windowHeight); }; // get the formatted video element $.fn.videoBG.video = function(options) { $('html, body').scrollTop(-1); // video container var $div = $('
'); $div.addClass('videoBG') .css('position',options.position) .css('z-index',options.zIndex) .css('top',0) .css('left',0) .css('height',options.height) .css('width',options.width) .css('opacity',options.opacity) .css('overflow','hidden'); // video element var $video = $('