Skip to content

Instantly share code, notes, and snippets.

@fregante
Last active December 24, 2018 11:53
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fregante/7330016 to your computer and use it in GitHub Desktop.
Save fregante/7330016 to your computer and use it in GitHub Desktop.
Method to add delays at any position in Greensocks TimelineLite and TimelineMax (Javascript GSAP)
/**
* Add a delay at the end of the timeline (or at any label)
* @param {number} delay Seconds to wait
* @param {string} position Label name where to start the delay
*
* Usage: tl.addDelay(4); //easy!
*/
TimelineLite.prototype.addDelay = function (delay, position) {
var delayAttr;
if(typeof delay === 'undefined' || isNaN(delay)){
return this;//skip if invalid parameters
}
if (typeof position === 'undefined') {
delayAttr = '+=' + delay; //add delay at the end of the timeline
} else if (typeof position === 'string') {
delayAttr = position + '+=' + delay; //add delay after label
} else if(!isNaN(position)) {
delayAttr = delay + position; //if they're both numbers, assume absolute position
} else {
return this; //nothing done
}
return this.set({}, {}, delayAttr);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment