Dev.to WebDev 🛠 Dev 👁 2 📖 3 min read

A Scroll Animation Where the Headline Opens Into the Product (React + Motion)

A small window sits between the two halves of a headline. As you scroll, the halves slide apart and the window grows until it fills the screen and shows the product. It's a nice way to open a launch page: the headline is

A small window sits between the two halves of a headline. As you scroll, the halves slide apart and the window grows until it fills the screen and shows the product. It's a nice way to open a launch page: the headline is the first thing people read, and the product is the first thing they see once they move.

Here's how to build it in React with Motion. The whole trick is one clip-path: inset() that starts as the size of a slot in the headline and ends at zero.

The structure

<section style={{ height: "300svh" }}>          {/* 3 screens of scrolling */}
  <div className="sticky top-0 h-svh overflow-hidden">  {/* the stage stays put */}
    <h1>
      <motion.span style={{ x: startX }}>Ship the site</motion.span>
      <span ref={slotRef} className="h-24 w-40" />   {/* the hole the window starts in */}
      <motion.span style={{ x: endX }}>this week</motion.span>
    </h1>
    <motion.div style={{ clipPath }} className="absolute inset-0">
      {/* full-screen product scene */}
    </motion.div>
  </div>
</section>

The section is three screens tall, but the stage inside is sticky and one screen tall, so it stays pinned while you scroll through the section. Scroll progress through the section becomes the animation's timeline.

Step 1: scroll progress

const { scrollYProgress } = useScroll({
  target: sectionRef,
  offset: ["start start", "end end"],
});
const openness = useTransform(scrollYProgress, [0, 0.6], [0, 1]);

openness goes from 0 to 1 over the first 60% of the section. The last 40% is a resting phase where the window is fully open and the pitch fades in, so people have time to read before the next section arrives.

Step 2: measure the slot once

The window has to start exactly where the empty slot in the headline is. Measure the slot's distance from each edge of the stage, and re-measure only when the stage resizes:

useEffect(() => {
  const stage = stageRef.current;
  if (!stage) return;
  const measure = () => {
    const box = stage.getBoundingClientRect();
    const hole = slotRef.current?.getBoundingClientRect();
    if (!hole) return;
    slot.set({
      top: hole.top - box.top,
      right: box.right - hole.right,
      bottom: box.bottom - hole.bottom,
      left: hole.left - box.left,
    });
  };
  measure();
  const observer = new ResizeObserver(measure);
  observer.observe(stage);
  return () => observer.disconnect();
}, []);

Step 3: one clip-path, shrinking to zero

inset(top right bottom left) cuts that much off each edge. At the start the insets are the slot's distances, so only the slot-sized window shows. Multiply them by 1 - openness and they shrink to zero, which opens the window to the full stage:

const clipPath = useTransform(() => {
  const inset = slot.get();
  if (!inset) return "inset(50%)"; // stay shut until measured
  const closed = 1 - openness.get();
  const radius = 20 * closed;
  return `inset(${inset.top * closed}px ${inset.right * closed}px ${inset.bottom * closed}px ${inset.left * closed}px round ${radius}px)`;
});

The round radius shrinks too, so the window starts as a rounded card and ends as a sharp full screen. Returning inset(50%) before the first measurement avoids a one-frame flash of the full scene on load.

Step 4: part the headline

const startX = useTransform(openness, [0, 1], ["0vw", "-40vw"]);
const endX = useTransform(openness, [0, 1], ["0vw", "40vw"]);
const titleOpacity = useTransform(openness, [0, 0.7], [1, 0]);

The two halves slide off in opposite directions and fade out before the window is fully open, so the headline never sits on top of the product.

Accessibility and reduced motion

  • The empty slot is aria-hidden, so screen readers just read the headline.
  • With prefers-reduced-motion, skip the scroll entirely: make the section one screen tall and feed the transforms a motion value fixed at 1, so the window shows fully open.
  • Keep a small "Scroll to open" hint at the bottom, fading out with the headline, so people know to scroll.

Why clip-path and not scale

Scaling the scene from small to full size would also "open" it, but the content inside would scale too, so the product would look tiny and blurry at the start. A clip-path keeps the scene at full size the whole time and only changes how much of it you see.

The full component

The finished version (React + Tailwind + Motion), with the reveal of the pitch and the reduced-motion state, is free on DeliverWebsite UI: https://ui.deliverwebsite.com/components/scroll-animations/aperture-scroll/

📰 Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.