Make your landing page feel alive

Move your pointer through the words

The prompt

Written from your settings. Paste it into your AI tool.

Animate the main headline in the hero section of my landing page with an effect called Evaporate. Make the headline evaporate into particles. Keep the real heading text in the page for layout, selection and screen readers, but make it transparent and draw the visible text on a canvas laid exactly over it. The canvas needs extra room above and around the text for particles to drift into. Draw the text onto an offscreen canvas in the same font, size, weight, letter spacing and line breaks as the real heading, then sample it on a grid of 3px cells. Every cell that touches any part of a letter, including its soft edges, becomes one particle with that cell as its home, so no outline of the letter is left behind when the particles go. Particles are set off by the pointer. Any particle whose home is within 0.7em of the pointer, measured against the size of the text, lets go, with a small random delay so the edge of the hole looks soft. This must work with a mouse and with a finger dragged across the text. A particle that has let go leaves a hole in the text where its home was. It drifts upward by roughly 1.4em with a little sideways wander, shrinks to half its size and fades to nothing over 1400ms. After it has gone its home stays empty for 900ms, then that piece of the letter fades back in over about 450ms. The particles are the same colour as the text. Each frame, draw the crisp text image first, cut out the homes of every particle that is away, then draw the drifting particles. Only run the animation loop while something is moving. Rebuild the particles if the heading changes size. If the visitor has prefers-reduced-motion turned on, do none of this and leave the plain heading as it is. Keep my existing font, colours and layout exactly as they are. Screen readers and search engines must still read the headline as one normal sentence, so put the full text in an aria-label on the heading and mark any decorative spans as aria-hidden. If the visitor has prefers-reduced-motion turned on, show the finished headline straight away with no animation. Make sure nothing shifts the layout while it plays. Use plain CSS and a little vanilla JavaScript, unless my project already has an animation library, in which case use that. A live demo with reference code for these exact settings is at https://smthngfun.com/a/evaporate and you can use that code as your starting point, adapted to my codebase and styling. If I am happy to credit the source, add a small "Animation by smthngfun" link to https://smthngfun.com in the footer of the page. Ask me before adding it.

Reference code

A working version of Evaporate with your settings. It assumes the headline has the class hero-title.

<!-- HTML -->
<!-- Evaporate animation from https://smthngfun.com/a/evaporate -->
<h1 class="hero-title">Make your landing page feel alive</h1>

/* CSS */
.hero-title { position: relative; }
.hero-title.evaporating .word { color: transparent; } /* the canvas draws the visible text */
.hero-title canvas { position: absolute; pointer-events: none; }

// JavaScript
const title = document.querySelector('.hero-title');
const text = title.textContent.trim();
title.setAttribute('aria-label', text);
title.innerHTML = text.split(/\s+/).map(function (word) {
  return '<span class="word" aria-hidden="true">' + word + '</span>';
}).join(' ');

if (!matchMedia('(prefers-reduced-motion: reduce)').matches) {
  const GRAIN = 3;      // particle size in px
  const LIFE = 1400;        // ms a particle takes to drift away
  const GAP = 900;          // ms its place stays empty
  const FORM = 450;              // ms to fade back in
  const tints = []; // empty means the text colour

  const canvas = document.createElement('canvas');
  canvas.setAttribute('aria-hidden', 'true');
  title.append(canvas);
  const ctx = canvas.getContext('2d');
  let picture, size, pad, cssW, cssH, ink;
  let homes = [];   // one entry per particle
  let frame = 0;
  let pointer = null;

  function build() {
    const cs = getComputedStyle(title);
    const box = title.getBoundingClientRect();
    const dpr = Math.min(2, window.devicePixelRatio || 1);
    size = parseFloat(cs.fontSize);
    pad = Math.ceil(size * 1.8);
    cssW = box.width + pad * 2;
    cssH = box.height + pad * 2;
    ink = cs.color;
    canvas.width = Math.round(cssW * dpr);
    canvas.height = Math.round(cssH * dpr);
    canvas.style.cssText = 'left:' + -pad + 'px;top:' + -pad + 'px;width:' + cssW + 'px;height:' + cssH + 'px';
    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);

    // A crisp picture of the text, drawn word by word where the real words sit.
    picture = document.createElement('canvas');
    picture.width = canvas.width;
    picture.height = canvas.height;
    const p = picture.getContext('2d', { willReadFrequently: true });
    p.scale(dpr, dpr);
    p.font = cs.fontWeight + ' ' + size + 'px ' + cs.fontFamily;
    p.fillStyle = ink;
    if ('letterSpacing' in p) p.letterSpacing = cs.letterSpacing === 'normal' ? '0px' : cs.letterSpacing;
    const m = p.measureText('Hg');
    const up = m.fontBoundingBoxAscent, down = m.fontBoundingBoxDescent;
    title.querySelectorAll('.word').forEach(function (word) {
      const r = word.getBoundingClientRect();
      p.fillText(word.textContent, r.left - box.left + pad, r.top - box.top + pad + (r.height - up - down) / 2 + up);
    });

    // Every grid cell that lands on a letter is a particle.
    const pixels = p.getImageData(0, 0, picture.width, picture.height).data;
    homes = [];
    for (let y = 0; y < cssH; y += GRAIN) {
      for (let x = 0; x < cssW; x += GRAIN) {
        // A cell counts if any part of it touches a letter, so soft edges go too and no outline is left.
        let touched = false;
        const x0 = Math.floor(x * dpr), y0 = Math.floor(y * dpr);
        const x1 = Math.min(picture.width, Math.ceil((x + GRAIN) * dpr));
        const y1 = Math.min(picture.height, Math.ceil((y + GRAIN) * dpr));
        for (let py = y0; py < y1 && !touched; py++) {
          for (let px = x0; px < x1 && !touched; px++) {
            touched = pixels[(py * picture.width + px) * 4 + 3] > 6;
          }
        }
        if (touched) {
          homes.push({ x: x, y: y, state: 0, from: 0, drift: 0, lift: 1, wobble: 0, tint: ink, sweep: 0 });
        }
      }
    }
    title.classList.add('evaporating');
    draw(performance.now());
  }

  function release(h, now) {
    h.state = 1;                       // 1 drifting, 2 gone, 3 forming again, 0 at rest
    h.from = now + Math.random() * 140;
    h.drift = Math.random() - 0.5;
    h.lift = 0.6 + Math.random() * 0.8;
    h.wobble = Math.random() * 6.28;
    h.tint = tints.length ? tints[Math.floor(Math.random() * tints.length)] : ink;
  }

  function draw(now) {
    let busy = false;
    if (pointer) {
      const box = title.getBoundingClientRect();
      const px = pointer.x - box.left + pad, py = pointer.y - box.top + pad;
      const reach = 0.7 * size;
      homes.forEach(function (h) {
        if (!h.state && (h.x - px) * (h.x - px) + (h.y - py) * (h.y - py) < reach * reach) release(h, now);
      });
    }

    ctx.clearRect(0, 0, cssW, cssH);
    ctx.globalAlpha = 1;
    ctx.drawImage(picture, 0, 0, cssW, cssH);
    // Cut out the homes of every particle that is away.
    homes.forEach(function (h) {
      if (!h.state) return;
      busy = true;
      if (h.state === 1 && now < h.from) return;
      ctx.clearRect(h.x, h.y, GRAIN, GRAIN);
    });
    // Then draw the particles.
    homes.forEach(function (h) {
      if (!h.state || now < h.from) return;
      const age = now - h.from;
      if (h.state === 1) {
        const t = age / LIFE;
        if (t >= 1) { h.state = 2; h.from = now; return; }
        const s = GRAIN * (1 - t * 0.5);
        ctx.globalAlpha = Math.pow(1 - t, 1.5);
        ctx.fillStyle = h.tint;
        ctx.fillRect(
          h.x + h.drift * t * size * 0.6 + Math.sin(t * 6 + h.wobble) * GRAIN * 1.5,
          h.y - Math.pow(t, 1.3) * 1.4 * size * h.lift,
          s, s);
      } else if (h.state === 2) {
        if (age >= GAP) { h.state = 3; h.from = now; }
      } else {
        const t = age / FORM;
        if (t >= 1) { h.state = 0; return; }
        ctx.globalAlpha = t;
        ctx.fillStyle = ink;
        ctx.fillRect(h.x, h.y, GRAIN, GRAIN);
      }
    });
    frame = busy || pointer ? requestAnimationFrame(draw) : 0;
  }

  function wake() { if (!frame) frame = requestAnimationFrame(draw); }

  document.addEventListener('pointermove', function (e) {
    const box = title.getBoundingClientRect();
    const near = e.clientX > box.left - pad && e.clientX < box.right + pad &&
      e.clientY > box.top - pad && e.clientY < box.bottom + pad;
    pointer = near ? { x: e.clientX, y: e.clientY } : null;
    wake();
  });
  document.addEventListener('pointerleave', function () { pointer = null; });

  document.fonts.ready.then(build);
  new ResizeObserver(function () { cancelAnimationFrame(frame); frame = 0; build(); }).observe(title);
}