Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
  <svg  id="svg" viewBox="0 0 600 2000">

    <polyline id="greenPath" points="50,50 500,200 200,500 300,800"/>

    <path class="limePath" d="M 50 50 L 500 200"/>
    <path class="limePath" d="M 500 200 L 200 500"/>
    <path class="limePath" d="M 200 500 L 300 800"/>
    
    <circle class="big" cx="50" cy="50" r="25" />
    <circle class="big" cx="500" cy="200" r="25" />
    <circle class="big" cx="200" cy="500" r="25" />
    <circle class="big" cx="300" cy="800" r="25" />
    
    <circle class="helper" cx="50" cy="50" r="2"/>
    
  </svg>
              
            
!

CSS

              
                body{
  margin:0;
  background-color:grey;
}
#svg{
  margin-top:100px;
  overflow:visible;
  visibility:hidden;
}
#greenPath{
  fill:none;
  stroke:green;
  stroke-width:8;
}
.limePath{
  fill:none;
  stroke:lime;
  stroke-width:2;
}
.big{
  fill:green;
  stroke:lime;
  stroke-width:2;
}
.helper{
  fill:red;
  stroke:none;
}
              
            
!

JS

              
                
const circles = gsap.utils.toArray(".big");
const pathSections = gsap.utils.toArray(".limePath");

gsap.set(circles[0], {rotation:18, transformOrigin:'center'});
gsap.set(circles[1], {rotation:195, transformOrigin:'center'});
gsap.set(circles[2], {rotation:-45, transformOrigin:'center'});
gsap.set(circles[3], {rotation:-110, transformOrigin:'center'});

gsap.set('#svg', {autoAlpha:1});


// helper: create STOPS of the 'greenPath' and move the 'helper' from -> to

let segments = 0;
let progressStops = [];
let route = document.querySelector("#greenPath");
let totalLength = document.querySelector("#greenPath").getTotalLength();
let ball = document.querySelector(".helper");

for (let i = 0; i < route.points.numberOfItems; i++) {
  var pos = route.points.getItem(i);

  if (i > 0) {
    segments += Math.sqrt(
      Math.pow(pos.x - prevPos.x, 2) + Math.pow(pos.y - prevPos.y, 2)
    );
  }
  progressStops.push((segments / totalLength).toFixed(6));
  prevPos = pos;
}

MotionPathPlugin.convertToPath( "#greenPath" );

let action = gsap.timeline({paused:true})
.to(ball, { 
  motionPath: {path: "#greenPath", align: "#greenPath", alignOrigin: [0.5, 0.5]},
  duration: 6, ease:'none'
});

action.progress(1).progress(0);

// master timeline

const dur = 3;

gsap.timeline({delay:1, repeat:-1, repeatDelay:1, defaults:{duration:dur, ease:'none'}})
.from(circles, {drawSVG:"0", stagger:dur*2})
.from(pathSections, {drawSVG:"0", stagger:dur*2},dur)
.to(action, { progress: progressStops[1]}, dur)
.to('#svg', {attr:{viewBox:'0 150 600 2000'}}, dur)
.to(action, { progress: progressStops[2]},dur*3)
.to('#svg', {attr:{viewBox:'0 450 600 2000'}}, dur*3)
.to(action, { progress: progressStops[3]},dur*5)
.to('#svg', {attr:{viewBox:'0 750 600 2000'}}, dur*5)

              
            
!
999px

Console