/*! * jQuery mini parallax * @author: me@habibhadi.com * @url: https://github.com/im4aLL/jQuery-mini-parallax * @version v1.0.0 */ !function(a,b){function h(b,c){this.element=b,this.options=a.extend({},g,c),this._defaults=g,this._name=e,this.__={initial:{}},this.ticking=!1,this.fetchedTransformValue=!1,this.fetchedBackgroundValue=!1,this.init()}var e="miniParallax",f=a(b),g={inset:1,speed:.5};h.prototype.init=function(){b.requestAnimFrame=function(){return b.requestAnimationFrame||b.webkitRequestAnimationFrame||b.mozRequestAnimationFrame||function(a){b.setTimeout(a,1e3/60)}}();var c=this;requestAnimFrame(function(){c.parallax()}),a(b).scroll(function(){c.ticking||(requestAnimFrame(function(){c.parallax()}),c.ticking=!0)})},h.prototype.getTransformValue=function(b){var c=this,d=a(b).css("transform");"none"!==d?(d=d.match(/(-?[0-9\.]+)/g),c.__.initial.tY=parseInt(d[5],10)):c.__.initial.tY=0,c.fetchedTransformValue=!0},h.prototype.getBpValue=function(){var b=this,c=a(b.element).css("backgroundPosition").split(" "),d=c[0],e=c[1];-1!==e.indexOf("%")?(e=parseFloat(e.substr(0,e.length-1)).toFixed(2),e=a(b.element).outerHeight()/100*e):e=parseFloat(e.replace(/[^0-9.]/g,"")).toFixed(2),b.__.initial.bpX=d,b.__.initial.bpY=e,b.fetchedBackgroundValue=!0},h.prototype.parallax=function(){var c=this,d=c.element;if(c.inViewport()){var e=c.options.speed,f=a(b).scrollTop(),g=a(b).height(),h=0,i=0;i=a(d).height();var j=a(d).data("parallax-item");"undefined"!=typeof j&&null!==j?(h=-(a(d).height()+a(d).offset().top-(g+f))*e,c.fetchedTransformValue||c.getTransformValue(j),h-=c.__.initial.tY,a(j).css("transform","translateY("+h+"px)")):(h=-(i-f)*e,c.fetchedBackgroundValue||c.getBpValue(),h-=c.__.initial.bpY,a(d).css("background-position",c.__.initial.bpX+" "+h+"px"))}c.ticking=!1},h.prototype.inViewport=function(){var b=this,c=a(b.element),d=b.options.inset<1?b.options.inset*c.height():0,e={top:f.scrollTop(),left:f.scrollLeft()};e.right=e.left+f.width(),e.bottom=e.top+f.height()-d;var g=c.offset();return g.right=g.left+c.outerWidth(),g.bottom=g.top+c.outerHeight(),!(e.rightg.right||e.bottomg.bottom)},a.fn[e]=function(b){return this.each(function(){a.data(this,"plugin_"+e)||a.data(this,"plugin_"+e,new h(this,b))})}}(jQuery,window,document);