Text Animation
揭示、闪烁、解码或替换文字,同时保持稳定的无障碍读值。
适用场景
- 当界面需要以下行为时使用 Text Animation:揭示、闪烁、解码或替换文字,同时保持稳定的无障碍读值。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/text-animation.json https://orvui.efu.me/r/text-scramble.json https://orvui.efu.me/r/chromatic-text-reveal.json https://orvui.efu.me/r/text-reveal.json https://orvui.efu.me/r/text-shimmer.json https://orvui.efu.me/r/text-cascade.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
Text Scramble
text-scramble.vue让临时字符逐步解析为目标文字,并提供稳定的无障碍读值。
Inspecting the repository
packages/vue/src/motion/text-animation/examples/text-scramble.vue
<script setup lang="ts">
import { ref } from "vue";
import { TextScramble } from "@/components/orvui/motion/text-animation";
const steps = ["Inspecting the repository", "Running the checks", "Preparing the update"];
const selected = ref(0);
function advance() { selected.value = (selected.value + 1) % steps.length; }
</script>
<template><div class="flex w-full flex-col items-center gap-8 text-center"><TextScramble :text="steps[selected]" class="font-mono text-xl font-medium text-foreground" /><button type="button" @click="advance" class="inline-flex h-9 items-center rounded-full border border-border bg-card px-4 text-xs font-medium text-foreground hover:border-border-strong">Next phrase</button></div></template>
packages/vue/src/motion/text-animation/src/TextScramble.vue
Dia Text Animation
chromatic-reveal.vue保持句子前缀静止,用色彩扫过显示不断变化的末尾词语。
Motion that feels natural.
packages/vue/src/motion/text-animation/examples/chromatic-reveal.vue
<script setup lang="ts">
import { ChromaticTextReveal } from "@/components/orvui/motion/text-animation";
const adjectives = ["natural.", "intentional.", "alive."];
</script>
<template><div class="@container flex w-full justify-center"><ChromaticTextReveal prefix="Motion that feels" :words="adjectives" :start-on-view="false" class="shrink-0 font-medium tracking-[-.04em] text-foreground [font-size:clamp(1.25rem,7.8cqw,3rem)]" /></div></template>
packages/vue/src/motion/text-animation/src/ChromaticTextReveal.vue
Text Reveal
reveal.vue用短距离上移和逐渐消退的模糊显示单词或字符。
Motion that feelsconsidered.
Word by word, with a soft blur.packages/vue/src/motion/text-animation/examples/reveal.vue
<script setup lang="ts">
import { ref } from "vue";
import { TextReveal } from "@/components/orvui/motion/text-animation";
const replay = ref(0);
</script>
<template><div class="flex w-full flex-col items-center gap-8 text-center"><div :key="replay" class="flex flex-col gap-2"><TextReveal as="h2" :text="['Motion that feels', 'considered.']" class="text-balance text-4xl font-semibold leading-[0.95] tracking-[-0.04em] text-foreground sm:text-5xl" /><TextReveal text="Word by word, with a soft blur." :delay=".9" :stagger=".05" :blur="6" y-offset="20%" class="text-sm text-muted-foreground" /></div><button type="button" @click="replay += 1" class="inline-flex h-9 items-center rounded-full border border-border bg-card px-4 text-xs font-medium text-foreground hover:border-border-strong">Replay</button></div></template>
packages/vue/src/motion/text-animation/src/TextReveal.vue
Text Shimmer
shimmer.vue在现有文字上移动高光,表示工作仍在进行或强调标签。
Loading projects…Faster shimmer
packages/vue/src/motion/text-animation/examples/shimmer.vue
<script setup lang="ts">
import { TextShimmer } from "@/components/orvui/motion/text-animation";
const examples = [{ text: "Loading projects…", class: "text-3xl font-semibold", duration: 2 }, { text: "Faster shimmer", class: "text-sm", duration: 1.5 }];
</script>
<template><div class="flex flex-col gap-4"><TextShimmer v-for="example in examples" :key="example.text" :duration="example.duration" :class="example.class">{{ example.text }}</TextShimmer></div></template>
packages/vue/src/motion/text-animation/src/TextShimmer.vue
逐字
cascade.vue逐字替换内容,让旧字符离开后新字符依次落定。
Install skills
packages/vue/src/motion/text-animation/examples/cascade.vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from "vue";
import { TextCascade } from "@/components/orvui/motion/text-animation";
const actions = ["Install skills", "Open settings", "Ship updates"];
const selected = ref(0);
let interval: ReturnType<typeof setInterval> | undefined;
onMounted(() => { interval = setInterval(() => selected.value = (selected.value + 1) % actions.length, 2400); });
onBeforeUnmount(() => clearInterval(interval));
</script>
<template><div class="flex w-full justify-center"><p class="text-lg font-medium text-foreground"><TextCascade :text="actions[selected]" /></p></div></template>
packages/vue/src/motion/text-animation/src/TextCascade.vue
状态与事件
此示例组合没有声明成对的受控属性与 update 事件。使用已列出的属性、原生事件和插槽组合内容;不要为它添加未公开的 v-model。
API 参考
Text Scramble
textstring—duration?numberMath.min(760, Math.max(420, target.length * 32))glyphs?string"ABCDEFGHJKLMNPQRSTUVWXYZ0123456789#%&@$?/"trigger?string | number—Dia Text Animation
prefixstring—wordsstring[]—colors?string[]() => ["#60a5fa", "#818cf8", "#c084fc", "#fb7185", "#fbbf24"]foregroundColor?string"var(--foreground)"duration?number1.2delay?number0pauseDuration?number.8loop?booleantruestartOnView?booleantrueonce?booleantrueinViewMargin?string—Text Reveal
textstring | string[]—as?string"span"split?"word" | "char""word"stagger?number.09delay?number0blur?number12yOffset?string | number"40%"spring?{ stiffness?: number; damping?: number; mass?: number; }—once?booleantruewhileInView?booleanfalse插槽
default() => VNodeChild#defaultText Shimmer
as?string"span"duration?number2spread?number2插槽
default() => VNodeChild#default逐字
textstring—无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Text Animation?
- 通过 text、as、split、stagger、delay、blur、yOffset、spring、once、whileInView 配置 Text Animation;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 通过default 插槽提供内容,应用副作用由调用方管理。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
更新于
来源与许可 ↗MIT · 0.1.1