I want to focus on "Motion One," which has official integration with Svelte through @motionone/svelte. This library by the same author of Framer Motion is sometimes informally called "Svelte Motion," but I think using the official name helps avoid confusion. The user mentioned "Svelte Motion" which could refer to that or perhaps the svelte-motion project. I remember it offers a Framer Motion-like API, but I think I'll stick to using the more well-known @motionone/svelte for advanced transitions.Checking API usage
I need to be careful not to provide incorrect library APIs. I could either answer in general terms about Svelte transitions and motion libraries without giving specific code, but since the user is developing a SvelteKit site, I think they'll appreciate code examples. I should mention the @motionone/svelte library, which is also informally called "Svelte Motion."
For example, to install, I'd say: npm install motion @motionone/svelte, and usage in Svelte would involve importing Motion and using it like <Motion.div animate={{ x: 100 }} transition={{ duration: 0.5 }}>...</Motion.div>, but I need to verify that this is correct for Svelte.Verifying Svelte motion usage
Let’s clarify how to use Motion One in Svelte based on the documentation. I see that I can import both animate and the Motion component:
The <Motion> component defaults to rendering a <div>, but I can also set it to render a different element like a <button>. I think I might also consider using the animate action from the "motion" library directly by attaching it with use:animate={{ ... }}, since @motionone/svelte exports both animate and Motion.Exploring Svelte transition options
I see an example using @motionone/svelte that shows how to set it up for animations in Svelte, which looks good. It involves importing animate and Motion, like this:
Since the user didn’t specify the library name but mentioned wanting advanced transitions for a SvelteKit site, they might be open to using Motion One. I'll consider suggesting setup for SvelteKit route transitions with advanced animations in a tutorial format.Structuring a SvelteKit tutorial
I can propose a structure for developing a SvelteKit site with advanced transitions using the Svelte Motion library. Here's the outline:
Initialize the SvelteKit app.
Install @motionone/svelte along with motion.
Create a base layout using <slot> and TransitionWrapper.
Implement page animations using the navigating store or the +layout.svelte file's life cycle events from $app/navigation.
Use the Motion component to manage fade and slide animations and potentially include the animate function for progress bars.
I need to acknowledge user preferences, especially if they refer to the "svelte-motion" library, but I feel confident moving forward with the official @motionone/svelte. I’ll mention how to use these features clearly, ensuring that if the user meant a different library, they can clarify.Planning a SvelteKit Transition Project
I believe this plan is mostly on track. While names of props may vary, I'm comfortable proceeding. I can implement advanced transitions, focusing on complex page transitions rather than shared layout transitions. I propose:
Build Navigation Animations: Animate link hovers.
Implement Page Transitions: Use Presence and Motion to handle entering and exiting pages.
Use Staggered Animations: Apply stagger to child elements, leveraging stagger from the motion library.
Create a Simple Project Structure: Include scaffolding for navigation and content.
I'll detail a step-by-step guide including project setup, code samples, and clarifications for any library assumptions.Structuring the SvelteKit Response
I believe bridging to the Motion library might not feel seamless. I think focusing on page transitions and staggered child animations is enough to illustrate "advanced" transitions. I could mention customizing transitions with the prefers-reduced-motion query, although the user may not need that detail.
I want to keep the response concise, so I’ll give a brief description, setup steps, and provide some Svelte code files along with notes on customizing transitions. I’ll keep the content straightforward without unnecessary filler. Let’s get to composing! Below is a minimal SvelteKit site wired up with route/page transitions and staggered content animations using Motion One’s Svelte bindings (@motionone/svelte). This is often what people mean by “Svelte Motion”; if you meant a different library (e.g. an NPM package literally named svelte-motion), the overall structure is the same but the imports/props will differ.
1. Create a SvelteKit project & install Motion One
delay: i * 0.08 creates a staggered entrance of cards.
whileHover / whileTap (Motion One convenience props) animate hover/tap states without writing extra handlers.
4. About page with a different animation flavor
A second route demonstrates that the same layout transition wrapper handles all pages. You can additionally animate elements within the page.
src/routes/about/+page.svelte:
svelte
<script lang="ts">
import { Motion } from '@motionone/svelte';
</script>
<section class="about">
<Motion
initial={{ opacity: 0, x: -20 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.4, easing: 'ease-out' }}
>
<h1>About this demo</h1>
<p>
Route transitions are implemented in the root <code>+layout.svelte</code>
using <code>Presence</code> and <code>Motion</code>. Each page is wrapped
in a motion container keyed on <code>$page.url.pathname</code>, so
navigation triggers coordinated enter and exit animations.
</p>
<p>
On this page we add an extra slide-in animation on the content itself,
independent of the higher-level page transition.
</p>
</Motion>
</section>
Direction-aware page transitions
Use $page.url.pathname and a small route ordering map to decide if a page should slide left/right or up/down based on navigation direction, and set initial/exit accordingly.
Scroll or in-view animations
Wrap sections in Motion with initial hidden state and animate them when they enter the viewport (with an IntersectionObserver and an {#if visible} block inside <Presence>).
Staggered children via JavaScript
Instead of delay: i * 0.08, you can use the stagger() helper from the motion package when you want to trigger a batch animation programmatically.
Reduced motion support
Respect prefers-reduced-motion via CSS or by swapping out the transition props (e.g. zero durations) if the user prefers no animation.
If you tell me which specific “Svelte Motion” package you’re using (e.g. @motionone/svelte vs an alternative), I can adjust the imports/props and add more targeted examples like shared-element transitions or more complex route-flow animations.