Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
window.setInterval(function() {
var position = element.css('background-position'),
positionX = Math.abs($.nounit(position.split(' ')[0])),
positionY = position.split(' ')[1],
frameWidth = 66,
numFrames = 8,
currentFrame = Math.floor(positionX / frameWidth),
nextFrame, nextFrameOffset;
nextFrame = (currentFrame == (numFrames - 1)) ? 0 : currentFrame + 1;
nextFrameOffset = nextFrame * frameWidth * -1;
element.css('background-position', nextFrameOffset + 'px ' + positionY);
}, 100);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.