[Lab 02]AWAIS MALIK

Pointer mask

A circle follows the pointer and reveals an inverted copy of the label underneath. Used on the main navigation.

  • CSS clip-path
  • Vanilla JS

Jump to the code ↓02 / 04

index.html4 lines
<a href="#" class="mask-link">
  Services
  <span class="mask-layer" aria-hidden="true">Services</span>
</a>
mask.css24 lines
.mask-link {
  position: relative;
  display: inline-block;
  overflow: hidden;
  padding: 0.65rem 1rem;
  background: #0d0d0c;
  color: #f1f0e8;
  font-family: ui-monospace, monospace;
  text-transform: uppercase;
}
/* Inverted copy of the label, clipped to a circle at the pointer */
.mask-layer {
  position: absolute;
  inset: 0;
  padding: inherit;
  background: #d6ff3b;
  color: #0d0d0c;
  pointer-events: none;
  clip-path: circle(0px at var(--x, 50%) var(--y, 50%));
  transition: clip-path 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}
.mask-link:hover .mask-layer {
  clip-path: circle(22px at var(--x, 50%) var(--y, 50%));
}
mask.js7 lines
document.querySelectorAll(".mask-link").forEach((link) => {
  link.addEventListener("pointermove", (e) => {
    const r = link.getBoundingClientRect();
    link.style.setProperty("--x", `${e.clientX - r.left}px`);
    link.style.setProperty("--y", `${e.clientY - r.top}px`);
  });
});

Next experiment

Letter roll →