-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimatinator.min.js
1 lines (1 loc) · 1.28 KB
/
animatinator.min.js
1
(function(e,t){var n=function(e){return parseInt(e)+"px"};t.fn.animatinator=function(e){var r=this;var i;r.currentFrame=0;var s={imgPath:"",dimx:0,dimy:0,frames:15,duration:1e3,startingFrame:0,start:{},stop:{},reverse:{}};var o=t.extend(s,e);r.startingFrame=o.startingFrame;var u=o.duration/o.frames;var a=new Array;for(var f=o.frames-1;f>-1;f--){a.push({"background-position":n(o.dimx*f)+" 0px"})}var l=a.pop();a.unshift(l);r.startAnimate=function(e,t){clearInterval(i);i=setInterval(function(){if(r.currentFrame<a.length){r.css(a[r.currentFrame]);r.currentFrame++}else{r.stopAnimate(e,t)}},u)};r.reverseAnimate=function(e,t){clearInterval(i);i=setInterval(function(){if(r.currentFrame>0){r.currentFrame--;r.css(a[r.currentFrame])}else{r.stopAnimate(e,t)}},u)};r.stopAnimate=function(e,t){clearInterval(i);i=undefined;if(typeof e=="function"){e(r,t)}};r.gotoFrame=function(e){var t=a[e];if(t){r.currentFrame=e;r.css(t)}};var c=function(e,t,n){if(typeof e=="number"){r.on(t,n)}else{r.on(e,function(e){n(t,e)})}};t.each(o.start,function(e,t){c(e,t,r.startAnimate)});t.each(o.reverse,function(e,t){c(e,t,r.reverseAnimate)});t.each(o.stop,function(e,t){c(e,t,r.stopAnimate)});r.css(t.extend({width:n(o.dimx),height:n(o.dimy),"background-image":"url('"+o.imgPath+"')"},a[r.currentFrame]));return r}})(window,jQuery)