Skip to content

Instantly share code, notes, and snippets.

@replete
Created April 14, 2012 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save replete/2384974 to your computer and use it in GitHub Desktop.
Save replete/2384974 to your computer and use it in GitHub Desktop.
Once-only sequential 'animation' (css classes) of element children on page load
/*
After the page loads, highlight important parts on the page (e.g. navigation),
by sequentially applying a css class to each, once.
Styles/animation handled by CSS.
*/
var $delayHoverAnims = $("[data-delay-hover-anim]");
$delayHoverAnims
.each(function () {
var $this = $(this),
$children = $this.children(),
delayTime = parseInt($this.attr("data-delay-hover-anim")),
initialDelay = 2000;
function flicker(e) {
var delay = $(e).index() * delayTime;
setTimeout(function () {
$(e)
.addClass("hover")
.delay(delayTime)
.queue(function (next) {
$(this).removeClass("hover");
next();
});
}, delay);
}
setTimeout(function () {
$children.each(function () {
flicker(this);
});
}, initialDelay);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment