Word Rotate <mv-word-rotate>

히어로 문장을 위한 인라인 회전 단어(슬라이드, 3D 플립, 블러, 페이드, 글자 단위)로, 너비가 부드럽게 바뀌어 문장이 튀지 않습니다.

작동 방식

히어로 문장을 위한 인라인 회전 단어(슬라이드, 3D 플립, 블러, 페이드, 글자 단위)로, 너비가 부드럽게 바뀌어 문장이 튀지 않습니다. 기본적으로 접근성을 갖추고 있습니다: 스크린 리더는 모든 선택지를 나열한 안정된 문장 하나를 듣고, 호버 시와 감싸는 링크에 포커스가 있을 때 멈추며, 화면 밖이나 숨겨진 탭에서는 일시 정지하고, 동작 줄이기 설정에서는 한 단어에 머뭅니다.

카테고리애니메이션 텍스트
유형Web Component (<mv-word-rotate>)
상태안정
Keywordsrotating-text, flip-words, text-loop, hero, headline, inline, layout-animation, accessible

When to use

  • A hero headline should cycle one inline word, like Build for designers, developers or teams
  • The rotating word should sit in a tinted pill whose width animates between words
  • A sold or public page needs a rotating word that screen readers hear once, not on every change
  • The word loop must be driven from script with next, previous or an index

Avoid when

  • A standalone word should melt into the next with a gooey blur → use Morphing Text instead
  • Whole phrases should be typed and deleted letter by letter → use Typewriter instead

설치

node scripts/add.mjs word-rotate --out ./src/marvelous

Marvelous UI MCP 서버를 사용하는 AI 에이전트: install_components({ slugs: ["word-rotate"], target_dir: "<absolute path>/src/marvelous", framework: "react" }).

복사되는 파일(의존성 포함): tokens/tokens.css, core/base.css, core/dom.js, core/element.js, core/motion.js, core/observe.js, components/word-rotate/word-rotate.js, components/word-rotate/word-rotate.css.

사용법

빠른 시작, 동작하는 가장 작은 마크업:

<p>Build for <mv-word-rotate words="designers, developers, teams"></mv-word-rotate></p>

기본 마크업입니다. 여기서 시작해 속성, data-*, CSS 변수로 커스터마이즈하세요:

<div style="display:grid;gap:2rem;width:min(100%,46rem);margin-inline:auto;text-align:center">
  <h2 style="margin:0;font:700 clamp(1.9rem,4.6vw,3.2rem)/1.15 var(--mv-font-display);letter-spacing:-.035em">
    Build for
    <mv-word-rotate data-variant="pill" words="designers, developers, teams" style="--mv-word-rotate-color:var(--mv-accent-fg)"></mv-word-rotate>
    <br>without the all-nighters.
  </h2>

  <div style="display:grid;gap:.9rem;font-size:clamp(1.1rem,2.4vw,1.45rem);font-weight:600;letter-spacing:-.02em">
    <p style="margin:0">Interfaces that feel <mv-word-rotate effect="flip" interval="2200" words="fast, reliable, elegant, accessible" colors="var(--mv-accent), var(--mv-info), var(--mv-success), var(--mv-warning)"></mv-word-rotate></p>
    <p style="margin:0">From prototype to <mv-word-rotate effect="blur" interval="2400" conjunction="and" words="production, launch, growth" style="--mv-word-rotate-color:var(--mv-accent)"></mv-word-rotate></p>
    <p style="margin:0;color:var(--mv-fg-muted)">Ships as <mv-word-rotate effect="slide" direction="down" interval="1800" words="HTML, React, Vue, Svelte, Astro" style="--mv-word-rotate-color:var(--mv-fg);font-family:var(--mv-font-mono)"></mv-word-rotate>, zero friction.</p>
    <p style="margin:0;color:var(--mv-fg-muted)">Looks <mv-word-rotate effect="fade" interval="2000" words="crisp, smooth, clean" style="--mv-word-rotate-color:var(--mv-fg)"></mv-word-rotate> by default.</p>
  </div>

  <p style="margin:0;font-size:.85rem;color:var(--mv-fg-muted)">Hover a word to hold it. Screen readers hear each sentence once, with every option.</p>
</div>

API

Attributes

Name유형DefaultDescription
wordsstringWords separated by commas (or |). Otherwise: one child per word.
effectslide | flip | blur | fadeslideTransition between two words; letters enter one after another.
intervalnumber (ms)2600How long each word is shown.
durationnumber (ms)560 (680 for flip)Duration of the transition and of the width glide.
staggernumber (ms)18-30 (0 for fade)Delay between letters.
easingCSS easingvar(--mv-ease-out)Letter easing curve (tokens accepted).
directionup | downupSlide / flip direction.
colorslist of CSS colorsOne color per word, cycled.
conjunctionor | and | noneorHow the screen reader sentence joins the words: “designers, developers, or teams”. Uses the page language (lang).
labelstringReplaces the screen reader sentence entirely.
pausedbooleanPauses the rotation. It also holds by itself on hover, on focus of a wrapping link or button, off-screen and in hidden tabs.
data-variantpillTinted pill whose width animates.
data-heldbooleanSet by the component while hover or focus holds the word (for styling).

Properties

Name유형Description
indexnumberCurrent word (settable, wraps around; assignable before the element is defined).

Methods

NameDescription
next()Next word.
previous()Previous word.

Events

NameDescription
mv-changeNew word shown (detail.index, detail.word).

CSS variables

NameDefaultDescription
--mv-word-rotate-colorinheritWord color.
--mv-word-rotate-durationDefault duration.
--mv-word-rotate-staggerDefault stagger.
--mv-word-rotate-easingLetter easing curve.
--mv-word-rotate-width-easingvar(--mv-ease-emphasized)Width glide easing curve.
--mv-word-rotate-radius0.3emPill corner radius.

Accessibility

The animated word is aria-hidden; a visually hidden sentence lists every option once (“designers, developers, or teams”, built with Intl.ListFormat in the page language), so screen readers never hear a change. There is no live region. The rotation holds while the pointer is on the word or while focus is inside a wrapping link or button, pauses off-screen and in hidden tabs, and under reduced motion shows one static word with no width animation. The pill keeps a visible outline in forced colors.

이 페이지는 AI로 번역되었습니다. 번역 문제 신고