Created
June 18, 2014 19:35
-
-
Save aderaaij/991e73960ad3397ed487 to your computer and use it in GitHub Desktop.
Sequentially add class to child
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
// 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