Getting Started
Components
Special Effects
Animations
Text Animations
Backgrounds
A vertical rotation of words
motion-sv
Word
word-rotate.svelte
<script lang="ts"> import { WordRotate } from "$lib/components/magic/word-rotate/index.js";</script>
<WordRotate as="h2" class="text-4xl font-bold text-black dark:text-white" words={["Word", "Rotate"]}/>Installation
pnpm dlx shadcn-svelte@latest add https://sv-animations.vercel.app/r/word-rotate.json
Install dependencies
Install the required packages for this component:
pnpm add motion-sv
Copy the Source Code
Copy and paste the following code into your project:
word-rotate.svelte
<script lang="ts"> import type { ClassValue } from "svelte/elements"; import { onMount } from "svelte"; import { motion, AnimatePresence, type MotionProps } from "motion-sv"; import { cn } from "#lib/utils.js";
type ElementType = "div" | "span" | "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
interface WordRotateProps { words: string[]; duration?: number; motionProps?: MotionProps; class?: ClassValue; as?: ElementType; }
let { words, duration = 2500, motionProps = { initial: { opacity: 0, y: -50 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: 50 }, transition: { duration: 0.25, ease: "easeOut" }, }, class: className, as = "h1", }: WordRotateProps = $props();
let MotionComponent = $derived(motion[as]);
let index = $state(0);
onMount(() => { const interval = setInterval(() => { index = (index + 1) % words.length; }, duration);
// Clean up interval on unmount return () => clearInterval(interval); });</script>
<!-- for some reason overflow hidden is not working - still in beta phase --><!-- Original React implementation use mode="wait" but the animation doesn't work properly in svelte --><!-- React Implmentaion : https://magicui.design/docs/components/word-rotate -->
<div class="overflow-hidden py-2"> <!-- mode="popLayout" initial={false} -->
<AnimatePresence mode="wait"> {#key words[index]} <MotionComponent class={cn(className)} initial={motionProps.initial} animate={motionProps.animate} exit={motionProps.exit} transition={motionProps.transition} > {words[index]} </MotionComponent> {/key} </AnimatePresence></div> index.ts
export { default as WordRotate } from "./word-rotate.svelte";export { default as RotatingTextContainer } from "./rotating-text-container.svelte";export { default as RotatingText } from "./rotating-text.svelte";export { useRotatingText } from "./use-rotating-text-context.svelte";
export type { RotatingTextContextType, UseIsInViewOptions, RotatingTextContainerProps, RotatingTextProps,} from "./types";Folder Structure
Folder Structure
src/└── lib/ └── components/ └── magic/ └── word-rotate/ ├── word-rotate.svelte └── index.tsInstall and integrate the Svelte component documented below.https://sv-animations.vercel.app/magic/docs/components/word-rotate/llms.txt
Follow the guide's installation and usage instructions.Match the project's existing structure, imports, and styles.Keep changes scoped to the component and verify it works.Reply with a short bullet list of completed changes.Usage
<script lang="ts"> import { WordRotate } from "#lib/components/magic/word-rotate/index.js";</script>
<WordRotate words={["Design", "Develop", "Ship"]} />Props
Word Rotate
A component for Word Rotate.
| Name | Type | Default | Description |
|---|---|---|---|
class | ClassValue | "" | Additional CSS classes to apply |
words | string[] | required | Array of words to rotate through |
duration | number | 2500 | Duration between word changes in milliseconds |
motionProps | MotionProps | { initial: { opacity: 0, y: -50 }, animate: { opacity: 1, y: 0 }, exit: { opacity: 0, y: 50 }, transition: { duration: 0.25, ease: 'easeOut' } } | Motion animation properties |