Pen Settings

HTML

CSS

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

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

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.

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 800 800">
  
  <path id="path" class="path" />
  
  <polyline id="handle-1" class="handle" points="100,400 200,300" />
  <polyline id="handle-2" class="handle" points="300,300 400,400 500,500" />
  <polyline id="handle-3" class="handle" points="600,500 700,400" />
  
  <rect id="anchor-1" class="anchor" x="-5" y="-5" width="10" height="10" />
  <rect id="anchor-2" class="anchor" x="-5" y="-5" width="10" height="10" />
  <rect id="anchor-3" class="anchor" x="-5" y="-5" width="10" height="10" />
  
  <circle id="control-1" class="control" r="5" />
  <circle id="control-2" class="control" r="5" />
  <circle id="control-3" class="control" r="5" />
  <circle id="control-4" class="control" r="5" />
</svg>
              
            
!

CSS

              
                body {
  background: #1d1d1d;
}

#svg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.path,
.handle {
  fill: none;
  stroke: #4e7fff;
  stroke-width: 2;
}

.anchor,
.control {
  fill: #4e7fff;  
  stroke: rgba(0,0,0,0.2);
  stroke-width: 1;
}
              
            
!

JS

              
                
gsap.registerPlugin(Draggable);

let path  = document.querySelector("#path");

let handle1 = document.querySelector("#handle-1").points;
let handle2 = document.querySelector("#handle-2").points;
let handle3 = document.querySelector("#handle-3").points;

let points = [
  handle1.getItem(0), // 0 - anchor1
  handle1.getItem(1), // 1 - cp1  
  handle2.getItem(0), // 2 - cp2
  handle2.getItem(1), // 3 - anchor2
  handle2.getItem(2), // 4 - cp3 
  handle3.getItem(0), // 5 - cp4
  handle3.getItem(1), // 6 - anchor3
];

let cp1 = createControl("#control-1", points[1]);
let cp2 = createControl("#control-2", points[2]);
let cp3 = createControl("#control-3", points[4]);
let cp4 = createControl("#control-4", points[5]);

let anchor1 = createAnchor("#anchor-1", points[0], cp1);
let anchor2 = createAnchor("#anchor-2", points[3], cp2, cp3);
let anchor3 = createAnchor("#anchor-3", points[6], cp4);

updatePath();

function createAnchor(element, point, handle1, handle2) {
  
  element = gsap.utils.toArray(element)[0];

  if (handle1 && handle2) {
    handle1.linkedHandle = handle2;
    handle2.linkedHandle = handle1;
  }

  gsap.set(element, { x: point.x, y: point.y });

  let draggable = new Draggable(element, {
    onDrag() {

      point.x = this.x;
      point.y = this.y;

      handle1 && handle1.update(this.deltaX, this.deltaY);
      handle2 && handle2.update(this.deltaX, this.deltaY);

      updatePath();
    }
  });
}

function createControl(element, point) {
  
  element = gsap.utils.toArray(element)[0];

  gsap.set(element, { x: point.x, y: point.y });

  let controlPoint = {
    linkedHandle: undefined,
    target: element,
    point,
    update(dx, dy) {      
      gsap.set(this.target, { x: `+=${dx}`, y: `+=${dy}` });
      this.point.x += dx;
      this.point.y += dy;
    }
  };

  let draggable = new Draggable(element, {
    onDrag() {

      point.x = this.x;
      point.y = this.y;

      if (controlPoint.linkedHandle) {        
        controlPoint.linkedHandle.update(-this.deltaX, -this.deltaY);
      }

      updatePath();
    }   
  });

  return controlPoint;
}  

function updatePath() {

  let p = points;

  path.setAttribute("d", `
    M${p[0].x},${p[0].y} C
     ${p[1].x},${p[1].y} ${p[2].x},${p[2].y} ${p[3].x},${p[3].y}  
     ${p[4].x},${p[4].y} ${p[5].x},${p[5].y} ${p[6].x},${p[6].y}`);
}
              
            
!
999px

Console