Created
April 14, 2012 14:53
-
-
Save replete/2384974 to your computer and use it in GitHub Desktop.
Once-only sequential 'animation' (css classes) of element children on page load
This file contains 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
/* | |
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