Skip to content

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";

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, when and onReveal. See Options.
  • Other attributes: the component gives them to the rendered element, for example class, id and aria-*. It also gives the attachments that you put on the component to the element.
  • children snippet: the component gives it revealed, which is true after the reveal. See Read the revealed state.
  • as changes: 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 img or input, because the component renders children
  • a tag whose children cannot hydrate, such as textarea, title, template or iframe

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.

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, except as. 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 when or threshold applies 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 }));

Returns an attachment that reveals the direct element children of the element. Its function accepts the options of reveal, and interval.

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.