Skip to content

Instantly share code, notes, and snippets.

@icodeforlove
Last active October 5, 2015 15:47
Show Gist options
  • Save icodeforlove/2829750 to your computer and use it in GitHub Desktop.
Save icodeforlove/2829750 to your computer and use it in GitHub Desktop.
helper for generating static css for keyframe animations
function generate_keyframe_animation (name, frames, height) {
var steps = [];
for (var frame = 0; frame < frames; frame++) {
var percent = ((frame / (frames - 1)) * 100).toFixed(2);
steps.push('\t' + percent + '% { background-position: 0px ' + (-height * frame) + 'px; }');
}
return '@-webkit-keyframes ' + name + ' {\n' + steps.join('\n') + '\n}';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment