Options
Depending on the use case, you can either use this library as-is (which applies some default options), or customize it to your liking. If you choose to do so, you can pass an object to this action containing your own options to be applied.
Keep in mind that these options are applied to the single DOM element you add Svelte Reveal to. For global and more in-depth settings, refer to the API section.
Fields
Fields are simple flags and values you can set on a specific element to change its Svelte Reveal behavior. Here you can find the list of all available fields.
disable
type: boolean
default: false
When set to false, the transition is disabled for the target element.
root
type: Element | Document | null
default: null
The root element used by the Intersection Observer.
rootMargin
type: string
default: "0px 0px 0px 0px"
The root margin property of the Intersection Observer.
threshold
type: number
default: 0.6
The threshold (in percentage from 0.0
to 1.0
) property used by the Intersection Observer to know when its target element is considered visible.
preset
type: “fade” | “slide” | “fly” | “spin” | “blur” | “scale”
default: "fade"
The transition preset that should be applied. Check out presets for more info.
reset
type: boolean
default: false
When set to true
, the node transitions out when out of view, and is revealed again when back in view.
duration
type: number
default: 800
How long the transition lasts (in ms).
delay
type: number
default: 0
How long the transition is delayed (in ms) before being triggered.
easing
type: Easing
default: "easeInOutCubic"
The easing function to use. Check out the full list of available easing functions and this other website to preview timing functions.
x
type: number
default: 0
The starting offset position in pixels on the x-axis.
y
type: number
default: 0
The starting offset position in pixels on the y-axis.
rotate
type: number
default: 0
The starting rotation offset in degrees.
opacity
type: number
default: 0
The starting opacity value.
blur
type: number
default: 0
The starting blur value in pixels.
scale
type: number
default: 1
The starting scale value in percentage. 1
corresponds to 100%
.
Callbacks
Here is a list of all the event callbacks we expose that you can hook into.
onRevealStart
signature: (node: HTMLElement) => void
Function that gets fired when the node starts being revealed.
onRevealEnd
signature: (node: HTMLElement) => void
Function that gets fired when the node is fully revealed.
onResetStart
signature: (node: HTMLElement) => void
Function that gets fired when the reset
option is set to true
and the node starts transitioning out.
onResetEnd
signature: (node: HTMLElement) => void
Function that gets fired when the reset
option is set to true
and the node has fully transitioned out.
onMount
signature: (node: HTMLElement) => void
Function that gets fired when the node is mounted on the DOM.
onUpdate
signature: (node: HTMLElement) => void
Function that gets fired when the action options are updated.
onDestroy
signature: (node: HTMLElement) => void
Function that gets fired when the node is unmounted from the DOM.
Presets
Presets are sets of options with predefined values, packaged under a name to achieve a certain transition effect. The following table shows the presets that come bundled with Svelte Reveal and which options they map to.
fade
The element fades in gracefully.
Mapped options
Resulting CSS
fly
The element fades in and moves along a translation on the y-axis.
Mapped options
Resulting CSS
slide
The element fades in and performs a translation on the x-axis.
Mapped options
Resulting CSS
blur
The element fades in and becomes unblurred.
Mapped options
Resulting CSS
scale
The element fades in and gets to the original size.
Mapped options
Resulting CSS
spin
The element fades in and gets to the original rotation degree.