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 class="wobble">
  Liquid SVG Button 💛
  <svg width="256" height="56" viewBox="0 0 256 56" fill="none" xmlns="http://www.w3.org/2000/svg">
    <defs>
      <linearGradient id="gradient" gradientTransform="rotate(90)">
        <stop offset="5%" stop-color="#7C3AED" />
        <stop offset="95%" stop-color="#8B5CF6" />
      </linearGradient>
      <filter id="shadow" filterUnits="userSpaceOnUse" height="200" width="512" y="0">
        <feDropShadow dx="0" dy="8" stdDeviation="8" flood-color="#7C3AED" flood-opacity="0.3" />
      </filter>
    </defs>
    <path id="baseBtnPath" d="M0 28C0 12.536 12.536 0 28 0H228C243.464 0 256 12.536 256 28C256 43.464 243.464 56 228 56H28C12.536 56 0 43.464 0 28Z" fill="transparent" />
  </svg>
</button>
<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" class="blob">
  <path fill="#FF0066" d="M60.7,-18.7C68.8,5.1,58.6,35.9,36.5,52.6C14.3,69.3,-19.9,71.9,-42.9,55.9C-65.9,40,-77.7,5.4,-68.7,-19.7C-59.7,-44.9,-29.8,-60.7,-1.8,-60.2C26.3,-59.6,52.6,-42.6,60.7,-18.7Z" transform="translate(100 100)" />
</svg>

<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg" class="blob">
  <path fill="#C4B5FD" d="M43,-45.3C54.5,-31.4,61.9,-15.7,64.4,2.5C66.9,20.7,64.4,41.3,52.9,54.9C41.3,68.4,20.7,74.9,4.3,70.7C-12.1,66.4,-24.2,51.3,-40.5,37.7C-56.9,24.2,-77.5,12.1,-83.1,-5.6C-88.7,-23.3,-79.3,-46.6,-63,-60.5C-46.6,-74.3,-23.3,-78.7,-3.8,-74.9C15.7,-71.1,31.4,-59.1,43,-45.3Z" transform="translate(100 100)" />
</svg>
<p class="debug-text">Toggle Debug Mode</p>
              
            
!

CSS

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

body {
  position: relative;
  display: grid;
  height: 100vh;
  place-items: center;
  background: #ede9fe;
  overflow: hidden;
  color: #4c1d95;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

svg {
  overflow: visible;
}

.wobble {
  position: relative;
  width: 256px;
  height: 56px;
  background: none;
  border: none;
  color: #f5f3ff;
  cursor: pointer;
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: 1rem;
  overflow: visible;
  outline: none;
}

.wobble svg {
  /*   filter: drop-shadow(0px 8px 16px rgba(139, 92, 246, 0.75)); */
  overflow: visible;
}

.wobble #btnPath {
  stroke: transparent;
  stroke-width: 3;
}

.wobble > * {
  pointer-events: none !important;
}

.wobble:focus #btnPath {
  stroke-width: 3;
  stroke: #fcd34d;
}

.wobble svg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
}

.toggle-points {
}

.blob {
  position: absolute;
  bottom: -25%;
  right: -25%;
  width: 50vw;
}

.blob path {
  fill: #ddd6fe;
}

.blob:nth-of-type(2) {
  top: -25%;
  left: -25%;
  bottom: auto;
  right: auto;
}

.debug-text {
  font-family: "Nunito", sans-serif;
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  cursor: pointer;
}

.debug-dot {
  opacity: 0;
}

.debug .debug-dot {
  opacity: 1 !important;
}

              
            
!

JS

              
                import SVG from "https://cdn.skypack.dev/svg.js";
import {
  spline,
  map
} from "https://cdn.skypack.dev/@georgedoescode/[email protected]";
import { Vector2D } from "https://cdn.skypack.dev/@georgedoescode/[email protected]";
import debounce from "https://cdn.skypack.dev/[email protected]";

let mousePos = new Vector2D(0, 0);
window.mouseHasMoved = false;

const svg = SVG(document.querySelector("svg"));
const path = document.getElementById("baseBtnPath");

const pointOrigins = pointsInPath(path, 32);
const points = pointsInPath(path, 32);
const bgPoints = pointsInPath(path, 32);

let btnPathData = spline(points, 1, true);
let bgPathData = spline(bgPoints, 1, true);

const bgPath = svg
  .path(btnPathData)
  .fill("#A78BFA")
  .attr("id", "bgPath")
  .attr("filter", "url(#shadow)");
const btnPath = svg
  .path(btnPathData)
  .fill("url(#gradient)")
  .attr("id", "btnPath");

const circles = [];

points.forEach((p) => {
  circles.push(
    svg.circle(4).cx(p.x).cy(p.y).fill("#4C1D95").attr("class", "debug-dot")
  );
});

function pointsInPath(path, numPoints = 10) {
  const pathLength = path.getTotalLength();
  const step = pathLength / numPoints;
  const points = [];

  for (let i = 0; i < pathLength; i += step) {
    points.push(path.getPointAtLength(i));
  }

  return points;
}

const pt = svg.node.createSVGPoint();
function transformCoords(evt) {
  pt.x = evt.clientX;
  pt.y = evt.clientY;

  return pt.matrixTransform(svg.node.getScreenCTM().inverse());
}

const range = 40;

(function animate() {
  if (window.mouseHasMoved) {
    points.forEach((p, index) => {
      const point = new Vector2D(pointOrigins[index].x, pointOrigins[index].y);
      const d = Vector2D.sub(point, mousePos);
      const l = Math.hypot(d.x, d.y);
      let y;

      if (l < range && !p.reset) {
        point.sub(new Vector2D(d.x, -(d.y * 0.675)));
        y = point.y;
      } else {
        y = pointOrigins[index].y;
      }

      p.y += (y - p.y) * 0.1;

      circles[index].attr("cy", p.y);
    });

    bgPoints.forEach((p, index) => {
      const point = new Vector2D(pointOrigins[index].x, pointOrigins[index].y);
      const d = Vector2D.sub(point, mousePos);
      const l = Math.hypot(d.x, d.y);
      let y;

      if (l < range && !p.reset) {
        point.sub(new Vector2D(d.x, -(d.y * 0.675)));
        y = point.y;
      } else {
        y = pointOrigins[index].y;
      }

      p.y += (y - p.y) * 0.05;
    });
  }

  bgPathData = spline(bgPoints, 1, true);
  bgPath.attr("d", bgPathData);

  btnPathData = spline(points, 1, true);
  btnPath.attr("d", btnPathData);

  requestAnimationFrame(animate);
})();

window.addEventListener("mousemove", (e) => {
  const { x, y } = transformCoords(e);

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

  mouseHasMoved = true;

  points.forEach((p, index) => {
    const point = new Vector2D(pointOrigins[index].x, pointOrigins[index].y);
    const d = Vector2D.sub(point, mousePos);
    const l = Math.hypot(d.x, d.y);

    if (l < range) {
      p.reset = false;
      debounce(() => {
        p.reset = true;
      }, 200)();
    } else {
      p.reset = false;
    }
  });

  bgPoints.forEach((p, index) => {
    const point = new Vector2D(pointOrigins[index].x, pointOrigins[index].y);
    const d = Vector2D.sub(point, mousePos);
    const l = Math.hypot(d.x, d.y);

    if (l < range) {
      p.reset = false;
      debounce(() => {
        p.reset = true;
      }, 200)();
    } else {
      p.reset = false;
    }
  });
});

document.querySelector(".debug-text").addEventListener("click", (e) => {
  if (document.body.classList.contains("debug")) {
    document.body.classList.remove("debug");
  } else {
    document.body.classList += "debug";
  }
});

              
            
!
999px

Console