Skip to content

Trigger reveal animations manually

By default, the viewport controls the entrance. The when option of React, Vue and Astro gives the control to your own state. @awesome-reveal/core does not have when.

Set when to true to reveal the element, and to false to reset the entrance. A reset has no exit animation. With no value or null, the viewport controls the entrance. A change from true to null keeps the element revealed.

In this example, a button shows and hides the details:

Your device asks for reduced motion, so the content shows with no animation.

import { useState } from "react";
import { Reveal } from "@awesome-reveal/react";
export function DetailsToggle() {
const [open, setOpen] = useState(false);
return (
<>
<button
type="button"
aria-expanded={open}
onClick={() => setOpen((open) => !open)}
>
Details
</button>
<Reveal when={open} hidden={!open} from={{ opacity: 0 }}>
The details.
</Reveal>
</>
);
}

In Astro, the when prop sets the value in the server HTML. In a client script, pass the rendered tag to getReveal, and set the when property of the result.

A change to when applies immediately. If when becomes false during the delay, the entrance resets and does not play.

The entrance plays one time. To play it again, set when to false, then to true.

when does not show or hide content. With false, the element is transparent, but screen readers read it, and the keyboard can focus its controls. To hide content, also set hidden, or do not render it. The example above sets hidden.

inert does not hide content. It only blocks focus, clicks and assistive technology.

Reduced motion has priority over when. If the user asks for reduced motion, the element reveals, also when when is false.

For focus in an element with when set to false, see Accessibility.

If an ancestor with overflow clips the element fully, the element does not reveal. An example is a carousel slide that its track clips. In React, Vue and Astro, set when to true when the slide becomes visible.

@awesome-reveal/core has no manual trigger. To play a waiting entrance, play the paused animations of the element:

import { reveal } from "@awesome-reveal/core";
reveal(".slide", { from: "left" });
export function playEntrance(slide) {
for (const animation of slide.getAnimations()) {
if (animation.playState === "paused") animation.play();
}
}

For a cascade, call getAnimations({ subtree: true }) on the container. The loop also plays your own paused animations of the element.