Skip to content

Instantly share code, notes, and snippets.

@panayotoff
Created January 29, 2014 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save panayotoff/8695826 to your computer and use it in GitHub Desktop.
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 ... )
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