Created
January 29, 2014 20:03
-
-
Save panayotoff/8695826 to your computer and use it in GitHub Desktop.
In a project, I needed very small filesize and great animation tool. TweenLite + CSSPlugin are great, but sometimes you need staggerTo(), which is part of TweenMax. So, I get this function out of TweenMax. Just add it and use it like TM.staggerTo( items, time, animation, stagger ... )
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
var TM = {}; | |
TM.staggerTo = function(targets, duration, vars, stagger, onCompleteAll, onCompleteAllParams, onCompleteAllScope) { | |
stagger = stagger || 0; | |
var delay = vars.delay || 0, | |
a = [], | |
finalComplete = function() { | |
if (vars.onComplete) { | |
vars.onComplete.apply(vars.onCompleteScope || this, arguments); | |
} | |
onCompleteAll.apply(onCompleteAllScope || this, onCompleteAllParams || []); | |
}, | |
l, copy, i, p; | |
if (!$.isArray(targets)) { | |
if (typeof(targets) === "string") { | |
targets = TweenLite.selector(targets) || targets; | |
} | |
if (TweenLite._internals.isSelector(targets)) { | |
targets = [].slice.call(targets, 0); | |
} | |
} | |
l = targets.length; | |
for (i = 0; i < l; i++) { | |
copy = {}; | |
for (p in vars) { | |
copy[p] = vars[p]; | |
} | |
copy.delay = delay; | |
if (i === l - 1 && onCompleteAll) { | |
copy.onComplete = finalComplete; | |
} | |
a[i] = new TweenLite(targets[i], duration, copy); | |
delay += stagger; | |
} | |
return a; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment