Skip to content

Instantly share code, notes, and snippets.

@mkuklis
Last active June 12, 2016 07:44
Show Gist options
  • Save mkuklis/5835614 to your computer and use it in GitHub Desktop.
Save mkuklis/5835614 to your computer and use it in GitHub Desktop.
run zepto.js animations in sequence
$.fn.queueAnim = function (steps, callback) {
var $selector = this;
function iterator(step) {
step.push(iterate);
$selector.animate.apply($selector, step);
}
function iterate() {
if (!steps.length) return callback && callback();
var step = steps.shift();
iterator(step);
}
iterate();
}
// example
$('div').queueAnim([
[ { 'rotate': '15deg' }, 200, 'ease-out' ],
[ { 'rotate': '-13deg' }, 300, 'ease-out' ],
[ { 'rotate': '10deg' }, 400, 'ease-out' ],
[ { 'rotate': '0deg' }, 500, 'ease-out' ]
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment