/*! * stellar.js v0.6.2 * http://markdalgleish.com/projects/stellar.js * * copyright 2013, mark dalgleish * this content is released under the mit license * http://markdalgleish.mit-license.org */ (function(f,k,m,d){var j="stellar",e={scrollproperty:"scroll",positionproperty:"position",horizontalscrolling:true,verticalscrolling:true,horizontaloffset:0,verticaloffset:0,responsive:false,parallaxbackgrounds:true,parallaxelements:true,hidedistantelements:true,hideelement:function(p){p.hide()},showelement:function(p){p.show()}},g={scroll:{getleft:function(p){return p.scrollleft()},setleft:function(p,q){p.scrollleft(q)},gettop:function(p){return p.scrolltop()},settop:function(p,q){p.scrolltop(q)}},position:{getleft:function(p){return parseint(p.css("left"),10)*-1},gettop:function(p){return parseint(p.css("top"),10)*-1}},margin:{getleft:function(p){return parseint(p.css("margin-left"),10)*-1},gettop:function(p){return parseint(p.css("margin-top"),10)*-1}},transform:{getleft:function(q){var p=getcomputedstyle(q[0])[i];return(p!=="none"?parseint(p.match(/(-?[0-9]+)/g)[4],10)*-1:0)},gettop:function(q){var p=getcomputedstyle(q[0])[i];return(p!=="none"?parseint(p.match(/(-?[0-9]+)/g)[5],10)*-1:0)}}},l={position:{setleft:function(p,q){p.css("left",q)},settop:function(p,q){p.css("top",q)}},transform:{setposition:function(r,t,q,s,p){r[0].style[i]="translate3d("+(t-q)+"px, "+(s-p)+"px, 0)"}}},a=(function(){var r=/^(moz|webkit|khtml|o|ms|icab)(?=[a-z])/,p=f("script")[0].style,q="",s;for(s in p){if(r.test(s)){q=s.match(r)[0];break}}if("webkitopacity" in p){q="webkit"}if("khtmlopacity" in p){q="khtml"}return function(t){return q+(q.length>0?t.charat(0).touppercase()+t.slice(1):t)}}()),i=a("transform"),c=f("
",{style:"background:#fff"}).css("background-position-x")!==d,b=(c?function(q,p,r){q.css({"background-position-x":p,"background-position-y":r})}:function(q,p,r){q.css("background-position",p+" "+r)}),h=(c?function(p){return[p.css("background-position-x"),p.css("background-position-y")]}:function(p){return p.css("background-position").split(" ")}),n=(k.requestanimationframe||k.webkitrequestanimationframe||k.mozrequestanimationframe||k.orequestanimationframe||k.msrequestanimationframe||function(p){settimeout(p,1000/60)});function o(q,p){this.element=q;this.options=f.extend({},e,p);this._defaults=e;this._name=j;this.init()}o.prototype={init:function(){this.options.name=j+"_"+math.floor(math.random()*1000000000);this._defineelements();this._definegetters();this._definesetters();this._handlewindowloadandresize();this._detectviewport();this.refresh({firstload:true});if(this.options.scrollproperty==="scroll"){this._handlescrollevent()}else{this._startanimationloop()}},_defineelements:function(){if(this.element===m.body){this.element=k}this.$scrollelement=f(this.element);this.$element=(this.element===k?f("body"):this.$scrollelement);this.$viewportelement=(this.options.viewportelement!==d?f(this.options.viewportelement):(this.$scrollelement[0]===k||this.options.scrollproperty==="scroll"?this.$scrollelement:this.$scrollelement.parent()))},_definegetters:function(){var p=this,q=g[p.options.scrollproperty];this._getscrollleft=function(){return q.getleft(p.$scrollelement)};this._getscrolltop=function(){return q.gettop(p.$scrollelement)}},_definesetters:function(){var p=this,s=g[p.options.scrollproperty],q=l[p.options.positionproperty],r=s.setleft,t=s.settop;this._setscrollleft=(typeof r==="function"?function(u){r(p.$scrollelement,u)}:f.noop);this._setscrolltop=(typeof t==="function"?function(u){t(p.$scrollelement,u)}:f.noop);this._setposition=q.setposition||function(w,y,v,x,u){if(p.options.horizontalscrolling){q.setleft(w,y,v)}if(p.options.verticalscrolling){q.settop(w,x,u)}}},_handlewindowloadandresize:function(){var p=this,q=f(k);if(p.options.responsive){q.bind("load."+this.name,function(){p.refresh()})}q.bind("resize."+this.name,function(){p._detectviewport();if(p.options.responsive){p.refresh()}})},refresh:function(r){var q=this,s=q._getscrollleft(),p=q._getscrolltop();if(!r||!r.firstload){this._reset()}this._setscrollleft(0);this._setscrolltop(0);this._setoffsets();this._findparticles();this._findbackgrounds();if(r&&r.firstload&&/webkit/.test(navigator.useragent)){f(k).load(function(){var u=q._getscrollleft(),t=q._getscrolltop();q._setscrollleft(u+1);q._setscrolltop(t+1);q._setscrollleft(u);q._setscrolltop(t)})}this._setscrollleft(s);this._setscrolltop(p)},_detectviewport:function(){var q=this.$viewportelement.offset(),p=q!==null&&q!==d;this.viewportwidth=this.$viewportelement.width();this.viewportheight=this.$viewportelement.height();this.viewportoffsettop=(p?q.top:0);this.viewportoffsetleft=(p?q.left:0)},_findparticles:function(){var p=this,s=this._getscrollleft(),r=this._getscrolltop();if(this.particles!==d){for(var q=this.particles.length-1;q>=0;q--){this.particles[q].$element.data("stellar-elementisactive",d)}}this.particles=[];if(!this.options.parallaxelements){return}this.$element.find("[data-stellar-ratio]").each(function(a){var e=f(this),c,h,u,d,z,t,g,y,w,b=0,f=0,v=0,x=0;if(!e.data("stellar-elementisactive")){e.data("stellar-elementisactive",this)}else{if(e.data("stellar-elementisactive")!==this){return}}p.options.showelement(e);if(!e.data("stellar-startingleft")){e.data("stellar-startingleft",e.css("left"));e.data("stellar-startingtop",e.css("top"))}else{e.css("left",e.data("stellar-startingleft"));e.css("top",e.data("stellar-startingtop"))}u=e.position().left;d=e.position().top;z=(e.css("margin-left")==="auto")?0:parseint(e.css("margin-left"),10);t=(e.css("margin-top")==="auto")?0:parseint(e.css("margin-top"),10);y=e.offset().left-z;w=e.offset().top-t;e.parents().each(function(){var i=f(this);if(i.data("stellar-offset-parent")===true){b=v;f=x;g=i;return false}else{v+=i.position().left;x+=i.position().top}});c=(e.data("stellar-horizontal-offset")!==d?e.data("stellar-horizontal-offset"):(g!==d&&g.data("stellar-horizontal-offset")!==d?g.data("stellar-horizontal-offset"):p.horizontaloffset));h=(e.data("stellar-vertical-offset")!==d?e.data("stellar-vertical-offset"):(g!==d&&g.data("stellar-vertical-offset")!==d?g.data("stellar-vertical-offset"):p.verticaloffset));p.particles.push({$element:e,$offsetparent:g,isfixed:e.css("position")==="fixed",horizontaloffset:c,verticaloffset:h,startingpositionleft:u,startingpositiontop:d,startingoffsetleft:y,startingoffsettop:w,parentoffsetleft:b,parentoffsettop:f,stellarratio:(e.data("stellar-ratio")!==d?e.data("stellar-ratio"):1),width:e.outerwidth(true),height:e.outerheight(true),ishidden:false})})},_findbackgrounds:function(){var p=this,s=this._getscrollleft(),r=this._getscrolltop(),q;this.backgrounds=[];if(!this.options.parallaxbackgrounds){return}q=this.$element.find("[data-stellar-background-ratio]");if(this.$element.data("stellar-background-ratio")){q=q.add(this.$element)}q.each(function(){var e=f(this),u=h(e),c,h,v,d,a,t,z,x,g,b=0,f=0,w=0,y=0;if(!e.data("stellar-backgroundisactive")){e.data("stellar-backgroundisactive",this)}else{if(e.data("stellar-backgroundisactive")!==this){return}}if(!e.data("stellar-backgroundstartingleft")){e.data("stellar-backgroundstartingleft",u[0]);e.data("stellar-backgroundstartingtop",u[1])}else{b(e,e.data("stellar-backgroundstartingleft"),e.data("stellar-backgroundstartingtop"))}a=(e.css("margin-left")==="auto")?0:parseint(e.css("margin-left"),10);t=(e.css("margin-top")==="auto")?0:parseint(e.css("margin-top"),10);z=e.offset().left-a-s;x=e.offset().top-t-r;e.parents().each(function(){var i=f(this);if(i.data("stellar-offset-parent")===true){b=w;f=y;g=i;return false}else{w+=i.position().left;y+=i.position().top}});c=(e.data("stellar-horizontal-offset")!==d?e.data("stellar-horizontal-offset"):(g!==d&&g.data("stellar-horizontal-offset")!==d?g.data("stellar-horizontal-offset"):p.horizontaloffset));h=(e.data("stellar-vertical-offset")!==d?e.data("stellar-vertical-offset"):(g!==d&&g.data("stellar-vertical-offset")!==d?g.data("stellar-vertical-offset"):p.verticaloffset));p.backgrounds.push({$element:e,$offsetparent:g,isfixed:e.css("background-attachment")==="fixed",horizontaloffset:c,verticaloffset:h,startingvalueleft:u[0],startingvaluetop:u[1],startingbackgroundpositionleft:(isnan(parseint(u[0],10))?0:parseint(u[0],10)),startingbackgroundpositiontop:(isnan(parseint(u[1],10))?0:parseint(u[1],10)),startingpositionleft:e.position().left,startingpositiontop:e.position().top,startingoffsetleft:z,startingoffsettop:x,parentoffsetleft:b,parentoffsettop:f,stellarratio:(e.data("stellar-background-ratio")===d?1:e.data("stellar-background-ratio"))})})},_reset:function(){var t,s,r,q,p;for(p=this.particles.length-1;p>=0;p--){t=this.particles[p];s=t.$element.data("stellar-startingleft");r=t.$element.data("stellar-startingtop");this._setposition(t.$element,s,s,r,r);this.options.showelement(t.$element);t.$element.data("stellar-startingleft",null).data("stellar-elementisactive",null).data("stellar-backgroundisactive",null)}for(p=this.backgrounds.length-1;p>=0;p--){q=this.backgrounds[p];q.$element.data("stellar-backgroundstartingleft",null).data("stellar-backgroundstartingtop",null);b(q.$element,q.startingvalueleft,q.startingvaluetop)}},destroy:function(){this._reset();this.$scrollelement.unbind("resize."+this.name).unbind("scroll."+this.name);this._animationloop=f.noop;f(k).unbind("load."+this.name).unbind("resize."+this.name)},_setoffsets:function(){var p=this,q=f(k);q.unbind("resize.horizontal-"+this.name).unbind("resize.vertical-"+this.name);if(typeof this.options.horizontaloffset==="function"){this.horizontaloffset=this.options.horizontaloffset();q.bind("resize.horizontal-"+this.name,function(){p.horizontaloffset=p.options.horizontaloffset()})}else{this.horizontaloffset=this.options.horizontaloffset}if(typeof this.options.verticaloffset==="function"){this.verticaloffset=this.options.verticaloffset();q.bind("resize.vertical-"+this.name,function(){p.verticaloffset=p.options.verticaloffset()})}else{this.verticaloffset=this.options.verticaloffset}},_repositionelements:function(){var v=this._getscrollleft(),s=this._getscrolltop(),a,e,z,d,q,c,w,u=true,p=true,y,b,t,r,x;if(this.currentscrollleft===v&&this.currentscrolltop===s&&this.currentwidth===this.viewportwidth&&this.currentheight===this.viewportheight){return}else{this.currentscrollleft=v;this.currentscrolltop=s;this.currentwidth=this.viewportwidth;this.currentheight=this.viewportheight}for(x=this.particles.length-1;x>=0;x--){z=this.particles[x];d=(z.isfixed?1:0);if(this.options.horizontalscrolling){y=(v+z.horizontaloffset+this.viewportoffsetleft+z.startingpositionleft-z.startingoffsetleft+z.parentoffsetleft)*-(z.stellarratio+d-1)+z.startingpositionleft;t=y-z.startingpositionleft+z.startingoffsetleft}else{y=z.startingpositionleft;t=z.startingoffsetleft}if(this.options.verticalscrolling){b=(s+z.verticaloffset+this.viewportoffsettop+z.startingpositiontop-z.startingoffsettop+z.parentoffsettop)*-(z.stellarratio+d-1)+z.startingpositiontop;r=b-z.startingpositiontop+z.startingoffsettop}else{b=z.startingpositiontop;r=z.startingoffsettop}if(this.options.hidedistantelements){p=!this.options.horizontalscrolling||t+z.width>(z.isfixed?0:v)&&t<(z.isfixed?0:v)+this.viewportwidth+this.viewportoffsetleft;u=!this.options.verticalscrolling||r+z.height>(z.isfixed?0:s)&&r<(z.isfixed?0:s)+this.viewportheight+this.viewportoffsettop}if(p&&u){if(z.ishidden){this.options.showelement(z.$element);z.ishidden=false}this._setposition(z.$element,y,z.startingpositionleft,b,z.startingpositiontop)}else{if(!z.ishidden){this.options.hideelement(z.$element);z.ishidden=true}}}for(x=this.backgrounds.length-1;x>=0;x--){q=this.backgrounds[x];d=(q.isfixed?0:1);c=(this.options.horizontalscrolling?(v+q.horizontaloffset-this.viewportoffsetleft-q.startingoffsetleft+q.parentoffsetleft-q.startingbackgroundpositionleft)*(d-q.stellarratio)+"px":q.startingvalueleft);w=(this.options.verticalscrolling?(s+q.verticaloffset-this.viewportoffsettop-q.startingoffsettop+q.parentoffsettop-q.startingbackgroundpositiontop)*(d-q.stellarratio)+"px":q.startingvaluetop);b(q.$element,c,w)}},_handlescrollevent:function(){var q=this,r=false;var s=function(){q._repositionelements();r=false};var p=function(){if(!r){n(s);r=true}};this.$scrollelement.bind("scroll."+this.name,p);p()},_startanimationloop:function(){var p=this;this._animationloop=function(){n(p._animationloop);p._repositionelements()};this._animationloop()}};f.fn[j]=function(q){var p=arguments;if(q===d||typeof q==="object"){return this.each(function(){if(!f.data(this,"plugin_"+j)){f.data(this,"plugin_"+j,new o(this,q))}})}else{if(typeof q==="string"&&q[0]!=="_"&&q!=="init"){return this.each(function(){var r=f.data(this,"plugin_"+j);if(r instanceof o&&typeof r[q]==="function"){r[q].apply(r,array.prototype.slice.call(p,1))}if(q==="destroy"){f.data(this,"plugin_"+j,null)}})}}};f[j]=function(p){var q=f(k);return q.stellar.apply(q,array.prototype.slice.call(arguments,0))};f[j].scrollproperty=g;f[j].positionproperty=l;k.stellar=o}(jquery,this,document));