Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <svg id="demo" xmlns="http://www.w3.org/2000/svg" width="2000" height="800" viewBox="0 0 1000 400">
  <title>Distribute Demo</title>
<defs>
  <clipPath id="theClipPath">
  <rect x="350" y="219" width="300" height="80" fill="yellow" />
</clipPath>  
  
  </defs>

    <text transform="translate(500 340)" font-size="30" text-anchor="middle" font-weight="600" fill="#fff">{ MotionPath | Stagger | Distribute | Wrap | Random }</text>

  <g id="letters" fill="none" stroke="#FFF" stroke-miterlimit="10" stroke-width="2">
    <path id="bodyD" d="M50.48,206V94.16h44c31.52,0,57.28,25.12,57.28,56C151.76,180.88,126,206,94.48,206Z"/>
    <path id="bodyI1" d="M183.44,94.16V206"/>
    <path id="bodyS" d="M280.4,104.88c-7.2-4.64-18.24-7.52-28.16-7.52-19.68,0-32.48,8.48-32.48,21.6,0,37.44,67.2,18.24,66.88,59.84,0,16.48-14.88,27.2-37.92,27.2-14.08,0-29-6.24-38.24-15.68"/>
    <path id="tPipe1" d="M341,206V97"/>
    <path id="tBar1" d="M300.5,97h80"/>
    <path id="bodyR" d="M406.5,206V97.36h34.85c25.12,0,39.52,12,39.52,33.12,0,21.6-14.4,33.92-39.52,33.92l-34.35.1"/>
   <path id="rLeg" d="M480.07,206,449.5,164.5"/>
    <path id="bodyI2" d="M522,97V206"/>
    <path id="bodyB" d="M563.11,206V97h45c21.6,0,34.08,7.24,34.08,24.84,0,14.08-8,23.52-22.08,25.92,17.76,2.08,28,12.48,28,28.32,0,19-14.56,29.92-40,29.92Z"/>
    <path id="bodyU" d="M677.19,97v63.56c0,29,16.16,45.44,44.32,45.44s44.32-16.48,44.32-45.44V97"/>
    <path id="tPipe2" d="M825,206V97"/>
    <path id="tBar2" d="M784.5,97h80"/>
    <path id="bodyE" d="M958,97H888.06V206h72.16"/>
    <path id="eBar" d="M950.5,148.5h-62"/>
  </g>
  
  <line id="underline" x1="480" y1="300" x2="520" y2="300" stroke-width="2" stroke="#88ce02" opacity="0"/>
  <g id="container"></g>

  <g clip-path="url(#theClipPath)">
   
      <text id ="end" transform="translate(500 284)" font-size="48" text-anchor="middle" font-weight="600" fill="#fff">GSAP 3</text>
  </g>
  
</svg>
<a href="https://twitter.com/Craig_PointC" target="_blank" title="Follow Craig on Twitter">
<img id="avatar" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/314556/craigmasternew.png" width="100" height="141" alt="Craig's Avatar">
  </a>


<a href="https://greensock.com"><img class="gsap-3-logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/gsap-3-logo.svg" width="150" /></a>
            
          
!
            
              body {
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100vh;
  overflow: hidden;
  align-items: center;
  justify-content: center;
  font-family: "Signika Negative", sans-serif;
  background: #262626;
}

svg {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  opacity: 0;
}

#avatar {
  position: fixed;
  bottom: 0;
  left: 10px;
}

.gsap-3-logo {
  width: 20vw;
  max-width: 150px;
  position: fixed;
  bottom: 15px;
  right: 15px;
}

            
          
!
            
              gsap.registerPlugin(MotionPathPlugin, DrawSVGPlugin);
console.clear();
let paths = document.querySelectorAll("path");
const svgns = "http://www.w3.org/2000/svg";
let container = document.querySelector("#container");
let targets = [];
let targetArrays = [];
let localTargets = [];
let size = 10; // use for width and height of rectangles
let fillFactor = 0.65; // percentage - how densely packed each path is with rectangles
const color = "#46a2e0";
const anim = gsap.timeline({ delay: 0.75 });




// make a bunch of rectangles to put on the 14 paths
for (let i = 0; i < paths.length; i++) {
  let pathPoints = MotionPathPlugin.getRawPath(paths[i])[0];
  let pathLength = MotionPathPlugin.getLength(paths[i]);
  let count = Math.floor(pathLength / size * fillFactor);
  let newX = pathPoints[0];
  let newY = pathPoints[1];
  localTargets = [];
  for (let j = 0; j < count; j++) {
    let newRect = document.createElementNS(svgns, "rect");
    container.appendChild(newRect);
    gsap.set(newRect, {
      x: newX,
      y: newY,
      fill: color,
      attr: {
        rx: 0,
        ry: 0,
        x: 0,
        y: 0,
        width: size,
        height: size
        }
    });
    localTargets.push(newRect);
    targets.push(newRect);
  }

  targetArrays.push(localTargets);
}

gsap.set("svg", { opacity: 1 });

// get the rectangles centered and ready for motion
gsap.set(targets, {
  xPercent: -50,
  yPercent: -50,
  transformOrigin: "50% 50%",
  scale: 0
});

// use drawSVG to animate in the paths
anim.from("path", {
  drawSVG: 0,
  duration: 1,
  stagger: {
    each: 0.1
  },
  ease: "none"
});

anim.to(targets, { scale: 1, ease: "elastic", duration: 1.25 });

// make an amimation for all 14 paths and the targets
for (let i = 0; i < targetArrays.length; i++) {
  anim.to(targetArrays[i], {
    motionPath: {
      path: paths[i],
      autoRotate: true,
      start: 0,
      end: gsap.utils.distribute({
        base: 0,
        amount: 1
      })
    },
    duration: 0.4
  });
}

// random colors
anim.to(targets, {
  fill: "random([#1bb1a5, #94c356, #e3aa59, #a63ba0, #cf5b21, #46a4cc])",
  duration: 0.45,
  ease: "none",
  stagger: {
    amount: 2,
    from: "end"
  }
});

// cycle scale with wrap()
anim.to(targets, {
  scale: gsap.utils.wrap([1.3, 1.6, 1.9, 2.2]),
  duration: 0.35,
  ease: "power3.inOut",
  stagger: {
    amount: 3,
    yoyo: true,
    repeat: 1
  }
});
// rectangles to circles and change to GreenSock green
anim.to(targets, {
  rotation: "+=360",
  duration: 0.75,
  fill: "#88ce02",
  attr: {
    rx: size / 2,
    ry: size / 2
  },
  stagger: {
    amount: 3,
    from: "end"
  }
});
// back to rectangles
anim.to(targets, {
  attr: {
    rx: 0,
    ry: 0
  }
});
// move all targets to central point
anim.to(
  targets,
  {
    x: 500,
    y: 300,
    rotation: 0,
    attr: {
      height: 2,
      width: 40
    },

    stagger: {
      amount: 1.3,
      from: "center"
    }
  },
  "+=0.5"
);
// bye bye targets
anim.set(targets, {
  opacity: 0
});
// hello underline
anim.set("#underline", {
  opacity: 1
});
// expand underline
anim.to("#underline", {
  attr: {
    x1: 200,
    x2: 800
  },
  ease: "power3.inOut"
});
// reveal GSAP 3.0 text with clipPath
anim.from("#end", {
  duration: 0.65,
  y: 340
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console