Scroll reveal set
Wrap anything to make it arrive as it scrolls into view: rise, clip wipe, scale, blur or slide, with an optional delay for staggering.
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type ElementType,
type ReactNode,
} from "react";
import "./reveal.css";
export type RevealEffect = "rise" | "clip" | "scale" | "blur" | "slide";
type RevealProps = {
children: ReactNode;
/** How the element arrives. */
effect?: RevealEffect;
/** Wait this many milliseconds after it enters the view. */
delay?: number;
/** Play again every time it re-enters (default: only the first time). */
repeat?: boolean;
as?: ElementType;
className?: string;
};
/**
* Reveal
* Wrap anything. It waits, hidden, until about a fifth of it is visible,
* then plays one of five entrances. Works inside any scrolling box too,
* because the browser clips the observer to scrolling parents.
*/
export function Reveal({
children,
effect = "rise",
delay = 0,
repeat = false,
as: Tag = "div",
className = "",
}: RevealProps) {
const ref = useRef<HTMLElement>(null);
const [shown, setShown] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const io = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setShown(true);
if (!repeat) io.disconnect();
} else if (repeat) {
setShown(false);
}
},
// Start a little before the bottom edge so it never pops in late.
{ threshold: 0.2, rootMargin: "0px 0px -6% 0px" },
);
io.observe(el);
return () => io.disconnect();
}, [repeat]);
return (
<Tag
ref={ref}
className={`gu-reveal ${className}`}
data-effect={effect}
data-shown={shown}
style={{ "--gu-reveal-delay": `${delay}ms` } as CSSProperties}
>
{children}
</Tag>
);
}
Paste this into ChatGPT, Claude, Cursor, v0, Lovable or Bolt. It describes the layout, motion, colors and accessibility and includes the code, so the AI can rebuild it in any framework.
# Build this UI piece: Scroll reveal set
You are a senior front-end engineer. Recreate the piece below in my project. If I don't say which framework I use, ask once, then build it in that framework (React, Vue, Svelte, Angular, Astro, plain HTML/CSS/JS or anything else). Keep the behavior, motion, colors, spacing and accessibility exactly as described. Keep the code clean and commented for beginners.
## What it is
A wrapper that keeps any element hidden until about a fifth of it is on screen, then plays one of five entrances. Use it on cards, headings, images and section blocks, and pass a growing delay to stagger a row.
## Behavior and motion
- An IntersectionObserver with threshold 0.2 and rootMargin "0px 0px -6% 0px" (so it starts a little before the bottom edge). It also works inside any scrolling box, because the observer is clipped by scrolling parents.
- Plays once by default. With `repeat`, it hides again when it leaves and replays when it comes back.
- Effects (hidden state, all returning to normal over 0.7–1s with cubic-bezier(0.16, 1, 0.3, 1)):
- rise: opacity 0, translateY(32px)
- clip: clip-path inset(100% 0 0 0) plus translateY(12px), wiping open from the bottom
- scale: opacity 0, scale(0.88)
- blur: opacity 0, blur(14px)
- slide: opacity 0, translateX(-40px)
- `delay` (ms) becomes a CSS variable used as transition-delay.
## Look
No styling of its own: it only animates what you wrap. The demo is a 420px tall scrolling box with a big "Five ways in." heading and one card per effect (the first card orange #ff5a1f with ink text, the rest surface cards with a hairline border).
## Accessibility
- Content is in the page from the start, so screen readers and search engines always get it.
- prefers-reduced-motion: a 0.3s fade only, no movement, blur or wipe, and no delay.
## Props
children, effect ("rise" | "clip" | "scale" | "blur" | "slide", default rise), delay (ms), repeat (boolean), as (tag, default div), className.
## Reference implementation
The original is written in React with one plain CSS file. Dependencies: none (plain React and CSS). Translate it faithfully; do not add new libraries unless my framework needs them.
### Reveal.tsx
```tsx
"use client";
import {
useEffect,
useRef,
useState,
type CSSProperties,
type ElementType,
type ReactNode,
} from "react";
import "./reveal.css";
export type RevealEffect = "rise" | "clip" | "scale" | "blur" | "slide";
type RevealProps = {
children: ReactNode;
/** How the element arrives. */
effect?: RevealEffect;
/** Wait this many milliseconds after it enters the view. */
delay?: number;
/** Play again every time it re-enters (default: only the first time). */
repeat?: boolean;
as?: ElementType;
className?: string;
};
/**
* Reveal
* Wrap anything. It waits, hidden, until about a fifth of it is visible,
* then plays one of five entrances. Works inside any scrolling box too,
* because the browser clips the observer to scrolling parents.
*/
export function Reveal({
children,
effect = "rise",
delay = 0,
repeat = false,
as: Tag = "div",
className = "",
}: RevealProps) {
const ref = useRef<HTMLElement>(null);
const [shown, setShown] = useState(false);
useEffect(() => {
const el = ref.current;
if (!el) return;
const io = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setShown(true);
if (!repeat) io.disconnect();
} else if (repeat) {
setShown(false);
}
},
// Start a little before the bottom edge so it never pops in late.
{ threshold: 0.2, rootMargin: "0px 0px -6% 0px" },
);
io.observe(el);
return () => io.disconnect();
}, [repeat]);
return (
<Tag
ref={ref}
className={`gu-reveal ${className}`}
data-effect={effect}
data-shown={shown}
style={{ "--gu-reveal-delay": `${delay}ms` } as CSSProperties}
>
{children}
</Tag>
);
}
```
### reveal.css
```css
/* One easing for every entrance: quick start, long soft landing. */
.gu-reveal {
--gu-reveal-ease: cubic-bezier(0.16, 1, 0.3, 1);
transition:
opacity 0.7s var(--gu-reveal-ease),
transform 0.9s var(--gu-reveal-ease),
clip-path 1s var(--gu-reveal-ease),
filter 0.8s var(--gu-reveal-ease);
transition-delay: var(--gu-reveal-delay, 0ms);
}
/* Hidden states, one per effect. */
.gu-reveal[data-shown="false"][data-effect="rise"] {
opacity: 0;
transform: translateY(32px);
}
.gu-reveal[data-shown="false"][data-effect="clip"] {
clip-path: inset(100% 0 0 0);
transform: translateY(12px);
}
.gu-reveal[data-shown="false"][data-effect="scale"] {
opacity: 0;
transform: scale(0.88);
}
.gu-reveal[data-shown="false"][data-effect="blur"] {
opacity: 0;
filter: blur(14px);
}
.gu-reveal[data-shown="false"][data-effect="slide"] {
opacity: 0;
transform: translateX(-40px);
}
/* Shown: everything back to normal. */
.gu-reveal[data-shown="true"] {
opacity: 1;
transform: none;
clip-path: inset(0 0 0 0);
filter: none;
}
/* Reduced motion: a short fade only, no movement, blur or wipe. */
@media (prefers-reduced-motion: reduce) {
.gu-reveal {
transition: opacity 0.3s linear;
transition-delay: 0ms;
}
.gu-reveal[data-shown="false"] {
transform: none !important;
clip-path: none !important;
filter: none !important;
}
}
```
You might also want
Next piece: Scroll-drawn timelineMarker highlight
Animations, beginner
Split text reveal
Animations, intermediate, needs motion
Text scramble
Animations, beginner