var createSprite = function (seletorCss) {
var hasNext = function () {
return current + 1 <= last;
};
var moveFrame = function (from, to) {
$el.removeClass(from).addClass(to);
};
var nextFrame = function () {
if(hasNext())
moveFrame(frames[current],frames[++current]);
}
var reset = function () {
moveFrame(frames[current], frames[0]);
current = 0;
}
var isFinished = function () {
return !hasNext();
}
var $el = $(seletorCss);
var frames = [
'frame1', 'frame2', 'frame3', 'frame4', 'frame5', 'frame5', 'frame6',
'frame7', 'frame8', 'frame9'
]
var current = 0; //frame atual
var last = frames.length - 1; //último frame
$el.addClass(frames[current]);
return {
nextFrame: nextFrame,
reset: reset,
isFinished: isFinished
}
}