Astro reveal API: Reveal and Cascade
@awesome-reveal/astro exports two components and the getReveal function. The components take the same options as props. For the supported versions, see Requirements.
import { Cascade, getReveal, Reveal } from "@awesome-reveal/astro";Reveal
Section titled “Reveal”Renders a tag around its children, and reveals the tag when it enters the viewport.
<Reveal as="section" from="left" class="hero"> Hello</Reveal>- Props:
as,from,keyframes,duration,delay,thresholdandwhen. See Options. - Other attributes: the component gives them to the rendered tag, for example
classandid. as: aRevealTag. The default is"div".
The props go into the server HTML, so they must be values that JSON can serialize. To run code at the reveal, listen to the reveal event.
Cascade
Section titled “Cascade”Renders a tag around its children. When the tag enters the viewport, it reveals the direct element children one after the other. See Animate a list.
Cascade accepts the props of Reveal, and interval.
getReveal
Section titled “getReveal”Gives the control of the reveal of a tag that Reveal or Cascade rendered. Call it in a processed <script>. A <script is:inline> cannot import the package:
---import { Reveal } from "@awesome-reveal/astro";---
<button id="show">Show</button><Reveal id="details" when={false}> Details</Reveal>
<script> import { getReveal } from "@awesome-reveal/astro";
const reveal = getReveal(document.querySelector("#details")!);
document.querySelector("#show")!.addEventListener("click", () => { reveal.when = true; });</script>- Argument: the rendered tag, for example the element with the
idof the component. - Return value: a
RevealControlobject with the members in the table below. - Errors:
getRevealthrows anErrorfor any other element. The HTML parser can move the tag out of its place, for example out of a<p>. See Where to place a reveal. - Navigations: with the
<ClientRouter />, callgetRevealagain after each navigation, because the new page has new elements. See View transitions.
| Member | Type | Description |
|---|---|---|
when |
boolean | null |
Gets or sets the manual control. null gives the control to the viewport and keeps a revealed element revealed. |
revealed |
boolean |
true after the reveal. Read only. It is false until the client script attaches the element. |
The reveal event
Section titled “The reveal event”The rendered tag dispatches a reveal event when the reveal starts. The event bubbles, so you can listen on an ancestor or on document. See Run code when the reveal starts.
| Type | Description |
|---|---|
RevealProps |
The props of Reveal. |
CascadeProps |
The props of Cascade. |
RevealTag |
The tags that as accepts. See as. |
RevealControl |
The object that getReveal returns. |
RevealOptions |
The reveal options. |
CascadeOptions |
The cascade options. |
Side |
The sides of from. |
StartState |
The start state object of from. |