0.0.3 • Published 11 months ago

svelte-appear-transition v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
11 months ago

Logo

Svelte Appear Transition

An easy to use and SSR friendly Svelte action that transitions elements when they appear in the viewport.

Installation

npm i -D svelte-appear-transition

Examples

Fade in

<div
  use:appear={{
    from: {
      opacity: '0',
      transform: 'translateY(40px)',
      transitionTimingFunction: 'ease-out'
    },
    to: {
      opacity: '1',
      transform: 'translateY(0)'
    },
    duration: 500
  }}
>
  ...
</div>

Same transition, but using Tailwind to apply the default styles:

<div
  class="opacity-0 translate-y-10 duration-500 ease-out"
  use:appear={{
    to: {
      opacity: '1',
      transform: 'translateY(0)'
    }
  }}
>
  ...
</div>

Staggered slide up

{#each items as item, i}
  <div
    use:appear={{
      from: {
        transform: 'translateY(40px)',
        transitionDelay: `${i * 100}ms`,
        transitionTimingFunction: 'ease-out'
      },
      to: {
        transform: 'translateY(0)'
      },
      duration: 500
    }}
  >
    {item}
  </div>
{/each}

Usage

Settings

NameOptionalDefaultDescription
tox-A string of class names or a styling object to apply when the element is in view.
from-A string of class names or a styling object to apply by default.
duration500Duration of the transition in milliseconds.
threshold0.5Threshold at which the transition will be triggered. Either a single number or an array of numbers between 0.0 and 1.0.
bothWaysfalseWhether to apply the transition in both directions. Can be true only if from is defined.

Events

NameDescriptionExample
styletransitionstartFired right before a transition starts.on:styletransitionstart={(event) => { event as TransitionEvent }}
styletransitionendFired right after a transition ends.on:styletransitionend={(event) => { event as TransitionEvent }}

The detail property of TransitionEvent has the following shape:

{
  /** The element that triggered the transition. */
  element: HTMLElement;
  /** The settings that were passed to the action. */
  transition: TransitionSettings;
  /** The direction of the transition. */
  direction: 'in' | 'out';
}
0.0.3

11 months ago

0.0.2

1 year ago

0.0.1

1 year ago