Created
April 19, 2018 04:36
-
-
Save maburdi94/ffbacb7afd8d424bfb3301598c54de04 to your computer and use it in GitHub Desktop.
NodeList prototype extension for WebAnimations (w/ stagger option)
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
interface AnimationOptions { | |
stagger?: number; | |
} | |
NodeList.prototype.animate = function(keyframes: AnimationKeyFrame | AnimationKeyFrame[], options: number | AnimationOptions) { | |
const elements: HTMLElement[] = Array.prototype.slice.call(this); | |
(function next(elements: Array<HTMLElement>) { | |
if (elements.length < 1) return; | |
setTimeout(() => { | |
elements[0].animate(keyframes, options); | |
// call next() recursively | |
next(elements.slice(1)); | |
}, typeof options =="object" ? options.stagger : 0); | |
})(elements); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment