Skip to content

Instantly share code, notes, and snippets.

@aderaaij
Created June 18, 2014 19:35
Show Gist options
  • Save aderaaij/991e73960ad3397ed487 to your computer and use it in GitHub Desktop.
Save aderaaij/991e73960ad3397ed487 to your computer and use it in GitHub Desktop.
Sequentially add class to child
// add class to next child
$.fn.add_class = function(options) {
var opts = $.extend({}, $.fn.add_class.defaults, options);
return this.each(function() {
var children = opts.child;
var index = 0;
function addClassToNextChild() {
if (index == children.length) return;
children.eq(index++).addClass(opts.usedclass);
window.setTimeout(addClassToNextChild, opts.delay);
}
addClassToNextChild();
});
}
$.fn.add_class.defaults = {
child: $('article'),
usedclass: 'is-active',
delay: 200
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment