/
greyforest-background-videos.min.js
9 lines (9 loc) · 2.09 KB
/
greyforest-background-videos.min.js
1
2
3
4
5
6
7
8
9
/*!=======================================================================================
* Greyforest Background Videos v1.0.1
* Lazy-loading + auto-playing (muted) videos that fill the background of their container
* https://www.greyforest.media/plugins
* https://github.com/GreyforestMedia
* ___ License
* by Greyforest Media
*/
function gfBackgroundVideos(e){var i="<style>"+e+" {position:relative;overflow:hidden;background-size:cover;background-position:center center;background-repeat:no-repeat;}"+e+" .bg-video-glass {position:absolute;height:100%;width:100%;z-index:2;top:0;left:0;margin:0;padding:0;}"+e+" .bg-video-wrapper {position:absolute;top:0;left:0;width:100%;height:100%;z-index:0;margin:0;padding:0;}"+e+" .bg-video-wrapper video {position:absolute;width: 100%; height: 100%; z-index: 0;margin:0;padding:0;object-fit:cover}<style>";$(e).length&&($("head").append(i),$(e).each(function(e){var i,o,t,a,d,s,r;i=void 0!==$(this).data("bg-video-poster")?$(this).data("bg-video-poster"):"",t=void 0!==$(this).data("bg-video-glass")?(o=$(this).data("bg-video-glass"),1==/^#[0-9A-F]{6}$/i.test(o)?o:"url("+o+");background-repeat:no-repeat;background-size:100% 100%;background-position:center center;"):"none",a=void 0!==$(this).data("bg-video-glassopacity")?$(this).data("bg-video-glassopacity"):"0.3",$(this).append('<div class="bg-video-wrapper" style="display:none"></div>'),$(this).css("background-image","url("+i+")"),$(this).children().not(".bg-video-wrapper").css("z-index","3"),void 0!==$(this).data("bg-video-sources")&&(d=$(this).data("bg-video-sources").split(","),s="",r=/(?:\.([^.]+))?$/,$.each(d,function(e,i){var o=r.exec(i)[1];s+='<source src="'+i+'" type="video/'+o+'">'}),$(window).bind("load",function(){$(".bg-video-wrapper").html('<span class="bg-video-glass" style="opacity:'+a+";background:"+t+'"></span><video autoplay playsinline loop muted poster="'+i+'" width="100%" height="100%" class="bg-video-player">'+s+"</video>").delay(1e3).fadeIn(800)}),$(this).removeAttr("data-bg-video-sources").removeData("bg-video-sources"),$(this).removeAttr("data-bg-video-poster").removeData("bg-video-poster"))}))}