Blog

Site animations without framer-motion: just what the browser already has

2 min read

Site animations without framer-motion: just what the browser already has

diyorjon.uz is a static, fast site. I wanted it to feel more alive, but I didn't want to add framer-motion or GSAP to the bundle and lose Lighthouse points. So every animation is built on things the browser already ships. Here's what I used and where to be careful.

1. Scroll reveals: IntersectionObserver

The Reveal component watches an element and sets data-state="shown" once it enters the viewport. The animation itself lives in CSS: opacity and transform. Two rules matter:

  • Nothing on the first screen gets hidden. Otherwise content blinks out for a moment when the page opens.
  • Content stays visible without JS. Hiding only starts inside useEffect, i.e. in the browser.

To make cards appear one after another, each gets delay={(i % 3) * 90}.

2. Tilt and magnetic buttons: one global listener

Instead of an onMouseMove on every card, the whole site has a single pointermove listener. It finds the [data-tilt] or [data-magnetic] element under the cursor with closest() and updates style.transform inside requestAnimationFrame. React never re-renders.

const nextTilt = target?.closest<HTMLElement>('[data-tilt]');
tiltEl.style.transform =
    `perspective(1000px) rotateX(${(0.5 - py) * max}deg) rotateY(${(px - 0.5) * max}deg)`;

The light spot on the card comes from the same place: --mx / --my CSS variables move the centre of a radial-gradient. All of this only runs on (hover: hover) and (pointer: fine), i.e. devices with a mouse.

3. Page transitions and the flying cover: View Transitions

Next.js 16 works with React's <ViewTransition> component. Page content is wrapped with key={pathname}, so on every navigation the old page gets exit and the new one gets enter:

<ViewTransition enter="page-in" exit="page-out" default="none">
    {children}
</ViewTransition>

The image in the blog list and the cover on the post page share a name (cover-<slug>). The browser pairs them, and the image flies from its old position to the new one. The whole implementation is the same name in two places.

For the portfolio filter I used addTransitionType('portfolio-filter'). Card animations only fire for that transition type and stay quiet during normal page navigation.

4. Theme switch: a circle

Clicking the theme toggle calls document.startViewTransition(), and the theme changes inside it via flushSync. The snapshot of the new page is revealed from the click point with clip-path: circle().

5. Parallax without JS

The faint text behind each heading drifts slowly as you scroll. One line of CSS is enough: animation-timeline: view(). Browsers that don't support it simply keep it still.

Things to watch out for

  • Animate only transform and opacity to keep 60 fps.
  • Everything turns off with prefers-reduced-motion.
  • The canvas particles in the hero start in requestIdleCallback, and don't exist on phones at all.
  • There's no page animation on the first load: it delays LCP. More on that in a separate post.

Result

New libraries: 0. Lighthouse scores didn't drop, and the home page actually went up.