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

              
                <button>
  <svg width="232" height="64" viewBox="0 0 232 64" fill="none" xmlns="http://www.w3.org/2000/svg">
    <path id="btn-path" d="M32 1.5H200C216.845 1.5 230.5 15.1553 230.5 32C230.5 48.8447 216.845 62.5 200 62.5H32C15.1553 62.5 1.5 48.8447 1.5 32C1.5 15.1553 15.1553 1.5 32 1.5Z" fill="#7257FA" stroke="#352970" stroke-width="3" />
  </svg>
  <span>
    Hover me! 💛
  </span>
</button>
<svg class="mouse" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-mouse-pointer">
  <path d="M3 3l7.07 16.97 2.51-7.39 7.39-2.51L3 3z"></path>
  <path d="M13 13l6 6"></path>
</svg>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css2?family=Nunito:wght@700&display=swap");

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  height: 100vh;
  display: grid;
  place-items: center;
  background-image: radial-gradient(circle at 50%, #fff, #f0f1ff);
  font-family: "Nunito", system-ui, sans-serif;
  pointer-events: none;
}

button {
  position: relative;
  width: 232px;
  height: 64px;
  line-height: 64px;
  border: 0;
  background: none;
  color: #fff;
  font-weight: 700;
  font-size: 1.25rem;
  font-family: inherit;
  cursor: pointer;
  opacity: 0;
}

button svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  z-index: -1;
}

.point {
  opacity: 0;
}

.mouse {
  position: absolute;
  top: 0;
  left: 0;
  opacity: 0;
}

              
            
!

JS

              
                import {
  spline,
  pointsInPath,
  createCoordsTransformer
} from "https://cdn.skypack.dev/@georgedoescode/generative-utils@1.0.1";
import gsap from "https://cdn.skypack.dev/gsap@3.6.1";

gsap.registerPlugin(DrawSVGPlugin);

const buttonPath = document.getElementById("btn-path");

const dummy = {
  x: 40,
  y: window.innerHeight / 2
};

function createLiquidPath(path, options) {
  const svgPoints = pointsInPath(path, options.detail);
  const originPoints = svgPoints.map(({ x, y }) => ({ x, y }));
  const liquidPoints = svgPoints.map(({ x, y }) => ({ x, y }));

  const pointElements = liquidPoints.map((p) => {
    const point = createPoint(p.x, p.y, path.closest("svg"));

    return point;
  });

  const mousePos = { x: 0, y: 0 };
  const transformCoords = createCoordsTransformer(path.closest("svg"));

  const pointDistance = Math.hypot(
    originPoints[0].x - originPoints[1].x,
    originPoints[0].y - originPoints[1].y
  );
  const maxDist = {
    x: options.axis.includes("x") ? pointDistance / 2 : 0,
    y: options.axis.includes("y") ? pointDistance / 2 : 0
  };

  gsap.ticker.add(() => {
    for (let i = 0; i < pointElements.length; i++) {
      gsap.set(pointElements[i], {
        attr: {
          cx: liquidPoints[i].x,
          cy: liquidPoints[i].y
        }
      });
    }
    gsap.set(path, {
      attr: {
        d: spline(liquidPoints, options.tension, options.close)
      }
    });
  });

  gsap.fromTo(
    mousePos,
    {
      x: 0,
      y: 100
    },
    {
      x: 200,
      y: 100,
      onUpdate() {}
    }
  );

  window.addEventListener("mousemove", (e) => {
    if (e.target.nodeName) return;

    console.log(e.target.nodeName);
    const { x, y } = transformCoords(e);

    mousePos.x = x;
    mousePos.y = y;

    liquidPoints.forEach((point, index) => {
      const pointOrigin = originPoints[index];
      const distX = Math.abs(pointOrigin.x - mousePos.x);
      const distY = Math.abs(pointOrigin.y - mousePos.y);

      if (distX <= options.range.x && distY <= options.range.y) {
        const difference = {
          x: pointOrigin.x - mousePos.x,
          y: pointOrigin.y - mousePos.y
        };

        const target = {
          x: pointOrigin.x + difference.x,
          y: pointOrigin.y + difference.y
        };

        const x = gsap.utils.clamp(
          pointOrigin.x - maxDist.x,
          pointOrigin.x + maxDist.x,
          target.x
        );

        const y = gsap.utils.clamp(
          pointOrigin.y - maxDist.y,
          pointOrigin.y + maxDist.y,
          target.y
        );

        gsap.to(point, {
          x: x,
          y: y,
          ease: "sine",
          overwrite: true,
          duration: 0.175,
          onComplete() {
            gsap.to(point, {
              x: pointOrigin.x,
              y: pointOrigin.y,
              ease: "elastic.out(1, 0.3)",
              duration: 1.25
            });
          }
        });
      }
    });
  });
}
function createPoint(x, y, target) {
  const el = document.createElementNS("http://www.w3.org/2000/svg", "circle");

  el.setAttribute("r", 3);
  el.setAttribute("cx", x);
  el.setAttribute("cy", y);

  el.setAttribute("fill", "#7257FA");

  el.classList.add("point");

  target.appendChild(el);

  return el;
}

createLiquidPath(buttonPath, {
  detail: 32,
  tension: 1,
  close: true,
  range: {
    x: 12,
    y: 40
  },
  axis: ["y"]
});

const tl = gsap.timeline({ repeat: -1, repeatDelay: 0.5 });

tl.to(
  "button",
  {
    opacity: 1
  },
  ">"
);

tl.to(
  "button span",
  {
    opacity: 0,
    delay: 0.5
  },
  ">"
);

tl.to(
  "button svg path",
  {
    stroke: "#fff",
    fill: "#fff",
    onComplete() {
      tl.timeScale(3);
    }
  },
  ">"
);

tl.to(
  ".point",
  {
    opacity: 1,
    delay: 0.5,
    stagger: 0.1,
    onComplete() {
      tl.timeScale(1);
    }
  },
  ">"
);

tl.to(
  "button svg path",
  {
    stroke: "#3C2E7F",
    duration: 0,
    drawSVG: 0
  },
  ">"
);

tl.to(
  dummy,
  {
    x: window.innerWidth - 40,
    yoyo: true,
    duration: 2,
    repeat: 1,
    delay: 0.5,
    onUpdate() {
      gsap.set(".mouse", {
        x: dummy.x,
        y: dummy.y,
        opacity: 1
      });
      const event = new MouseEvent("mousemove", {
        view: window,
        bubbles: true,
        cancelable: true,
        clientX: dummy.x,
        clientY: dummy.y
      });
      window.dispatchEvent(event);
    },
    onComplete() {
      gsap.to(".mouse", {
        // opacity: 0
      });

      tl.timeScale(0.375);
    }
  },
  ">"
);

tl.to(
  "button svg path",
  {
    drawSVG: "100%",
    delay: 0.25,
    onComplete() {
      tl.timeScale(1);
    }
  },
  ">"
);

tl.to(
  dummy,
  {
    x: window.innerWidth - 40,
    yoyo: true,
    duration: 2,
    repeat: 1,
    onUpdate() {
      gsap.set(".mouse", {
        x: dummy.x,
        y: dummy.y,
        opacity: 1
      });
      const event = new MouseEvent("mousemove", {
        view: window,
        bubbles: true,
        cancelable: true,
        clientX: dummy.x,
        clientY: dummy.y
      });

      window.dispatchEvent(event);
    },
    onComplete() {
      gsap.to(".mouse", {
        opacity: 0
      });
    }
  },
  ">"
);

tl.to(
  "button",
  {
    opacity: 0,
    delay: 0.5
  },
  ">"
);

              
            
!
999px

Console