Skip to content

Instantly share code, notes, and snippets.

@foxydot
Created February 5, 2015 05:35
Show Gist options
  • Save foxydot/ab8a23023ce7a0f5cb48 to your computer and use it in GitHub Desktop.
Save foxydot/ab8a23023ce7a0f5cb48 to your computer and use it in GitHub Desktop.
tween progress of items on path
$(window).ready(function() {
var quantity = 30, //number of dots
duration = 3, //duration (in seconds)
path = [{x:100, y:0}, {x:200, y:100}, {x:100, y:200}, {x:0, y:100},{x:100, y:0}]; //points on the path (BezierPlugin will plot a Bezier through these). Adjust however you please.
var tl = new TimelineMax({repeat:10, yoyo:true});
//we can remove the first point on the path because the position is already there and we want to draw the Bezier from there through the other points
//path.shift();
for (i = 0; i < quantity; i++) {
//create a new dot, add the .dot class, set the position, and add it to the body.
var dot = $("<div />", {id:"dot"+i}).addClass("dot").appendTo("body");
//create a tween for the dot that travels the full path of the bezier
var t = TweenMax.to(dot, duration, {bezier:{values:path, curviness:10}, paused:true, ease:Linear.easeNone});
//tween the progress of the tween so that each dot only travels a decreasing percentage of the full path
TweenLite.to(t, duration - (duration * i/quantity), {progress:1- i/quantity, ease:Linear.easeNone, delay:i*0.3});
}
});
body {
background-color: black;
}
.dot{
position: absolute;
width: 20px;
height: 20px;
background-color: #91e600;
border-radius: 50%;
top: 0;
left: 300px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment