Created
June 29, 2011 22:47
-
-
Save iammerrick/1055195 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.sprite = function(options){ | |
var $el = $(this) | |
, frames = options.frames | |
, inverse = options.inverse | |
, currentFrame = 1 | |
, size = options.size | |
, fps = options.duration / frames | |
, positions = ($(this).css('background-position').split(' ') || ' ') | |
, top = positions[1] | |
, left = positions[0] | |
, backgroundPosition; | |
function animate(){ | |
if(inverse){ | |
top = parseInt(top) - size; | |
} else{ | |
top = parseInt(top) + size; | |
} | |
$el.css('background-position', left+' '+top+'px'); | |
currentFrame++; | |
if(currentFrame < frames){ | |
setTimeout(animate, fps); | |
} | |
} | |
setTimeout(animate , fps); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment