forked from jquery-backstretch/jquery-backstretch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.backstretch.min.js
11 lines (11 loc) · 1.66 KB
/
jquery.backstretch.min.js
1
2
3
4
5
6
7
8
9
10
11
/*
* jQuery Backstretch
* Version 1.3
* http://srobbin.com/jquery-plugins/jquery-backstretch/
*
* Add a dynamically-resized background image to the page
*
* Copyright (c) 2011 Scott Robbin (srobbin.com)
* Dual licensed under the MIT and GPL licenses.
*/
(function(a){a.backstretch=function(j,f,i){var b={centeredX:true,centeredY:true,speed:0,constrain:false},p=a("#backstretch"),s=p.data("settings")||b,n=p.data("settings"),h=("onorientationchange" in window)?a(document):a(window),d,m,r,e,g,q,o,k;if(f&&typeof f=="object"){a.extend(s,f)}if(f&&typeof f=="function"){i=f}a(document).ready(l);return this;function l(){if(j){var t;if(p.length==0){p=a("<div />").attr("id","backstretch").css({left:0,top:0,position:"fixed",overflow:"hidden",zIndex:-999999,margin:0,padding:0,height:"100%",width:"100%"})}else{p.find("img").addClass("deleteable")}t=a("<img />").css({position:"absolute",display:"none",margin:0,padding:0,border:"none",zIndex:-999999}).bind("load",function(v){var u=a(this);u.css({width:"auto",height:"auto"});m=this.width||a(v.target).width();r=this.height||a(v.target).height();d=m/r;c(function(){u.fadeIn(s.speed,function(){p.find(".deleteable").remove();if(typeof i=="function"){i()}})})}).appendTo(p);if(a("body #backstretch").length==0){a("body").append(p)}p.data("settings",s);t.attr("src",j);a(window).resize(c)}}function c(v){try{k={left:0,top:0};var t=h.width(),u=h.height();g=(!s.constrain||t<m)?t:m;q=g/d;if(s.constrain&&q>r){q=r;g=q*d}if(s.centeredY){a.extend(k,{top:((u-q)/2)+"px"})}if(s.centeredX){a.extend(k,{left:((t-g)/2)+"px"})}a("#backstretch, #backstretch img").width(g).height(q).filter("#backstretch").css(k)}catch(w){}if(typeof v=="function"){v()}}}})(jQuery);