Skip to content

Instantly share code, notes, and snippets.

@andyfowler
Created August 12, 2010 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyfowler/521692 to your computer and use it in GitHub Desktop.
Save andyfowler/521692 to your computer and use it in GitHub Desktop.
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