🚨 Latest Research:Tanstack npm Packages Compromised in Ongoing Mini Shai-Hulud Supply-Chain Attack.Learn More →
Socket
Book a DemoSign in
Socket

animated-svelte

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

animated-svelte

A motion-like CSS animation library for Svelte.

latest
npmnpm
Version
0.0.0
Version published
Maintainers
1
Created
Source

animated-svelte

A motion-like CSS animation library for Svelte 5, providing declarative animations with a simple and intuitive API. This all happens using the in and out directives provided by Svelte.

[!WARNING] This strictly an internal package for now and not intended for public use eventually I may get around the making this public.

pnpm add animated-svelte

Quick Start

pnpm add animated-svelte

[!WARNING] The rest of this documentation was written by AI and my not be completely accurate.

<script>
	import { animated } from 'animated-svelte';
</script>

<animated.div
	initial={{ opacity: 0, scale: 0 }}
	animate={{ opacity: 1, scale: 1 }}
	transition={{ duration: 300 }}
>
	Hello, animated-svelte!
</animated.div>

Components

animated.div and animated.span

Animated versions of standard HTML elements with motion capabilities.

Props

PropTypeDescription
initialPartial<AnimationConfig> | falseInitial animation state (before entering)
animatePartial<AnimationConfig>Target animation state
exitPartial<AnimationConfig>Exit animation state (when leaving)
transitionPartial<TransitionConfig>Transition configuration
refHTMLElement | nullReference to the DOM element

Animation Properties

The AnimationConfig type supports the following properties:

  • opacity - number (0-1)
  • scale - number
  • rotate - number (degrees)
  • x - number \| string (px or percentage)
  • y - number \| string (px or percentage)
  • width - number \| string (px or percentage)
  • height - number \| string (px or percentage)
  • filter - string (CSS filter value)

Transition Configuration

type TransitionConfig = {
	duration: number | `${number}s` | `${number}ms`; // Default: 0
	timingFunction: 'linear' | 'ease' | 'ease-in' | 'ease-out' | 'ease-in-out'; // Default: 'ease-out'
	delay: number | `${number}s` | `${number}ms`; // Default: 0
};

Examples

Basic Animation

<animated.div animate={{ rotate: 90 }} transition={{ duration: 0.5, timingFunction: 'ease-out' }}>
	Rotating element
</animated.div>

Enter/Exit Animations

<script>
	import { animated } from 'animated-svelte';

	let isVisible = $state(false);
</script>

<button onclick={() => (isVisible = !isVisible)}> Toggle </button>

{#if isVisible}
	<animated.div
		initial={{ opacity: 0, scale: 0 }}
		animate={{ opacity: 1, scale: 1 }}
		exit={{ opacity: 0, scale: 0 }}
		transition={{ duration: 0.2 }}
	>
		Fade in and scale up
	</animated.div>
{/if}

Position Animation

<animated.div initial={{ x: 0 }} animate={{ x: 100 }} transition={{ duration: 0.5 }}>
	Moving element
</animated.div>

Stagger Animation

{#each Array.from({ length: 5 }) as _, i (i)}
	<animated.div
		initial={{ opacity: 0, y: 20 }}
		animate={{ opacity: 1, y: 0 }}
		transition={{
			duration: 0.3,
			delay: i * 0.1
		}}
	>
		Item {i + 1}
	</animated.div>
{/each}

Resize Animation

<animated.div
	initial={{ width: 50, height: 50 }}
	animate={{ width: 100, height: 100 }}
	transition={{ duration: 0.5 }}
>
	Resizing element
</animated.div>

Combined Animations

<animated.div
	initial={{ rotate: 90, opacity: 0, scale: 0 }}
	animate={{ rotate: 0, opacity: 1, scale: 1 }}
	transition={{ duration: 0.5, timingFunction: 'ease-out' }}
>
	Multiple properties animated together
</animated.div>

Advanced Usage

Using the useAnimation Hook

For custom components or more control, you can use the useAnimation hook directly:

<script>
	import { useAnimation } from 'animated-svelte';

	let elementRef = $state(null);

	const { enter, exit } = useAnimation({
		ref: () => elementRef,
		initial: () => ({ opacity: 0 }),
		animate: () => ({ opacity: 1 }),
		exit: () => ({ opacity: 0 }),
		transition: () => ({ duration: 0.3 })
	});
</script>

<div bind:this={elementRef} in:enter out:exit>Custom animated element</div>

Keywords

svelte

FAQs

Package last updated on 05 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts