-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.shifting.min.js
2 lines (2 loc) · 2.31 KB
/
jquery.shifting.min.js
1
2
/*! jquery.shifting 20-05-2014 */
!function(a,b,c){function d(b){this.options=a.extend({},h,b),this._defaults=h,this._name=g,this.props={windowHeight:0,windowWidth:0,scrollTop:0,scrollLeft:0},this.elDefault={selector:"",duration:"100%",delay:"0%",easing:"linear"},this.init()}function e(a,b,c,d,e){switch(a){case"linear":return d*b/e+c;case"easeInQuad":return b/=e,-d*b*(b-2)+c;case"easeOutQuad":return b/=e,-d*b*(b-2)+c;case"easeInOutQuad":return b/=e/2,1>b?d/2*b*b+c:(b--,-d/2*(b*(b-2)-1)+c);default:return d*b/e+c}}function f(a){return parseInt(a,10)/100}var g="shifting",h={update:10,prepare:!0,animation:{}},i={};d.prototype={init:function(){i=this,i.options.prepare&&i.prepare(),setInterval(i.run,i.options.update)},prepare:function(){a.each(i.options.animation,function(b,c){a(c.selector).each(function(){var b={};a.each(c.properties,function(a,c){b[a]=c[0]}),a(this).data(i._name+"_prepared")||i.posElement(a(this),b),a(this).data(i._name+"_prepared","true")})})},run:function(){i.setProps(),a.each(i.options.animation,function(b,c){a(c.selector).each(function(){$this=a(this),a(this).elementIsVisible(function(){var b=a.extend(i.elDefault,c),d=i.props.windowHeight*f(b.delay),e=i.props.windowHeight*f(b.duration),g=i.props.windowHeight+i.props.scrollTop-$this.offset().top;console.log("total: "+e+" – progress: "+g+" – delay: "+d),e+d>g&&g>d&&i.animate($this,b.easing,b.properties,e,g-d)})})})},animate:function(b,c,d,f,g){var h={};a.each(d,function(a,b){var d;d="opacity"==a||"scale"==a?3:1,h[a]=e(c,g,b[0],b[1]-b[0],f).toFixed(d)}),i.posElement(b,h)},posElement:function(b,c){var d=a.extend({translateX:0,translateY:0,scale:1,rotate:0,opacity:1},c);b.css({transform:"translate3d("+d.translateX+"px, "+d.translateY+"px, 0) scale("+d.scale+") rotate("+d.rotate+"deg)",opacity:d.opacity})},setProps:function(){i.props.windowHeight=b.innerHeight,i.props.windowWidth=b.innerWidth,i.props.scrollTop=a(c).scrollTop(),i.props.scrollLeft=a(c).scrollLeft()}},a[g]=function(a){return new d(a)},a.fn.elementIsVisible=function(b){var c={top:i.props.scrollTop,left:i.props.scrollLeft,right:i.props.scrollLeft+i.props.windowWidth,bottom:i.props.scrollTop+i.props.windowHeight},d=a(this).offset();d.right=d.left+a(this).outerWidth(),d.bottom=d.top+a(this).outerHeight(),c.right<d.left||c.left>d.right||c.bottom<d.top||c.top>d.bottom||b()}}(jQuery,window,document);