Svelte reveal API: components and attachments
@awesome-reveal/svelte exports two components and two attachments. They take the same options, as props or as a function that returns an object. For the supported versions, see Requirements.
import { Cascade, Reveal, cascade, reveal } from "@awesome-reveal/svelte";Reveal
Section titled “Reveal”Renders an element around its children, and reveals the element when it enters the viewport.
<Reveal as="section" from="left" class="hero">Hello</Reveal>- Props:
as,from,keyframes,duration,delay,threshold,whenandonReveal. See Options. - Other attributes: the component gives them to the rendered element, for example
class,idandaria-*. It also gives the attachments that you put on the component to the element. childrensnippet: the component gives itrevealed, which istrueafter the reveal. See Read the revealed state.aschanges: the component keeps its reveal.
as accepts an HTML tag or a custom element, such as my-card. It does not accept these tags:
- a void tag, such as
imgorinput, because the component renders children - a tag whose children cannot hydrate, such as
textarea,title,templateoriframe
Cascade
Section titled “Cascade”Renders an element around its children. When the element 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. It gives the same children snippet. onReveal gets the container.
reveal
Section titled “reveal”Returns an attachment that reveals the element.
<article {@attach reveal(() => ({ from: "left", onReveal: entered }))}> A card</article>- Argument: a function that returns the options of
Reveal, exceptas. With no argument, the attachment uses the default options. - Updates: the attachment reads the function in an effect. A change of the state that the function reads updates the options of the same reveal. A change of
whenorthresholdapplies immediately, and the other options apply at the next reveal. - Server rendering: the attachment does not run on the server, so the server HTML shows the element. See SvelteKit.
- New element: the reveal belongs to the element. A new element, such as one in a
{#key}block, starts a new reveal.
An attachment with fixed options can be in a module and serve many elements:
import { reveal } from "@awesome-reveal/svelte";
export const fadeIn = reveal(() => ({ from: { opacity: 0 }, duration: 400 }));cascade
Section titled “cascade”Returns an attachment that reveals the direct element children of the element. Its function accepts the options of reveal, and interval.
Stylesheet
Section titled “Stylesheet”The package imports its stylesheet, on the server and in the browser. It also exports the stylesheet as @awesome-reveal/svelte/reveal.css.
| Type | Description |
|---|---|
RevealProps |
The props of Reveal. |
CascadeProps |
The props of Cascade. |
RevealOptions |
The options that the function of reveal returns. |
CascadeOptions |
The options that the function of cascade returns. |
Side |
The sides of from. |
StartState |
The start state object of from. |