金融数字动效,专业实时呈现
简介
基于 Framer Motion 弹簧物理的金融数字动画方案,支持价格闪烁、动态格式化与实时行情展示,适用于交易仪表板和实时金融 UI
原始描述
Patterns for animating financial numbers with spring physics, formatting, and visual feedback. Covers animated counters, price tickers, percentage changes, and value flash effects. Use when building financial dashboards or trading UIs. Triggers on animated number, price animation, financial display, number formatting, spring animation, value ticker.
通过你的 Agent 添加
安装目录:animated-financial-display-design-system/(目录名取自 SKILL.md 的 frontmatter name,不是 URL 里的 slug)。
点「快速安装」复制一段指令贴给你的 Agent:它会先下载到 /tmp、把文件清单和校验值给你看,你确认之后才解压安装。不会一步装完、也不改系统其它位置。
或者手动安装
包是「根级 SKILL.md + 作者附带的文件」,解压到上面的 <slug>/ 目录即可;
目录名不用换,也不要把包直接解压到 skills 根目录。
技能申请的权限由作者决定:装之前先看清单里有没有脚本、它会读写什么。
中文使用说明 来自收录源
核心用法
本技能提供六套可复用的 React + TypeScript 模式,专为金融数字的动态展示设计:
- Spring-Animated Number — 利用
@react-spring/web实现数值平滑过渡,支持前缀/后缀、小数位配置与自定义动画时长 - Value Flash Effect — 数值变化时触发颜色闪烁反馈(上涨绿色/下跌红色),600ms 后自动复位,增强用户感知
- Financial Number Formatting — 封装
formatCurrency、formatPercentage、formatNumber三大工具函数,支持国际化、紧凑记数法(K/M/B)及灵活精度控制 - Price Ticker Component — 组合式行情卡片,集成动态价格、涨跌幅与视觉状态指示
- Metric Card with Animation — 带环比变化的指标卡片,自动计算涨跌幅并联动闪烁效果
- CSS Flash Animation — 纯 CSS 关键帧动画作为降级方案,避免 JS 动画阻塞
显著优点
- 物理真实感:弹簧动画(spring physics)比线性插值更符合人类对"价值变动"的认知预期
- 无障碍友好:强制使用
tabular-nums 消除数字跳变,确保视觉稳定性
- 工程完备性:涵盖工具函数、React 组件、CSS 动画三层抽象,适配不同性能场景
- 类型安全:完整 TypeScript 接口定义,便于接入设计令牌(design tokens)系统
潜在局限
- 依赖
@react-spring/web,对包体积敏感的项目需评估权衡
- 闪烁效果在高频更新场景(>5次/秒)可能造成视觉干扰,需配合节流或聚合策略
- 未内置 SSR 优化,服务端渲染时需处理 hydration 不匹配
适合人群
- 前端开发者构建加密货币交易所、股票交易终端、投资组合仪表板
- 需要为实时数据流添加"专业感"动效的产品团队
- 已采用 Tailwind CSS 或同类原子化 CSS 方案的技术栈
常规风险
- 性能风险:未节流的实时数据流 × 复杂弹簧配置 = 主线程阻塞;建议配合
requestAnimationFrame 或 Web Worker
- 精度风险:JavaScript 浮点运算在格式化前未做
decimal.js 类处理,极端金额场景可能出现末位误差
- 视觉风险:红绿配色默认假设色觉正常用户,建议叠加箭头或 +/- 符号以满足色盲无障碍标准
tabular-nums 消除数字跳变,确保视觉稳定性- 依赖
@react-spring/web,对包体积敏感的项目需评估权衡 - 闪烁效果在高频更新场景(>5次/秒)可能造成视觉干扰,需配合节流或聚合策略
- 未内置 SSR 优化,服务端渲染时需处理 hydration 不匹配
适合人群
- 前端开发者构建加密货币交易所、股票交易终端、投资组合仪表板
- 需要为实时数据流添加"专业感"动效的产品团队
- 已采用 Tailwind CSS 或同类原子化 CSS 方案的技术栈
常规风险
- 性能风险:未节流的实时数据流 × 复杂弹簧配置 = 主线程阻塞;建议配合
requestAnimationFrame 或 Web Worker
- 精度风险:JavaScript 浮点运算在格式化前未做
decimal.js 类处理,极端金额场景可能出现末位误差
- 视觉风险:红绿配色默认假设色觉正常用户,建议叠加箭头或 +/- 符号以满足色盲无障碍标准
- 性能风险:未节流的实时数据流 × 复杂弹簧配置 = 主线程阻塞;建议配合
requestAnimationFrame或 Web Worker - 精度风险:JavaScript 浮点运算在格式化前未做
decimal.js类处理,极端金额场景可能出现末位误差 - 视觉风险:红绿配色默认假设色觉正常用户,建议叠加箭头或 +/- 符号以满足色盲无障碍标准
技能正文
name: animated-financial-display
model: standard
description: Patterns for animating financial numbers with spring physics, formatting, and visual feedback. Covers animated counters, price tickers, percentage changes, and value flash effects. Use when building financial dashboards or trading UIs. Triggers on animated number, price animation, financial display, number formatting, spring animation, value ticker.
Animated Financial Display
Create engaging financial number displays with smooth animations, proper formatting, and visual feedback on value changes.
When to Use
- Building trading dashboards with live prices
- Showing portfolio values that update in real-time
- Displaying metrics that need attention on change
- Any financial UI that benefits from motion
Pattern 1: Spring-Animated Number
Using framer-motion's spring physics:
import { useSpring, animated } from '@react-spring/web';
import { useEffect, useRef } from 'react';
interface AnimatedNumberProps {
value: number;
prefix?: string;
suffix?: string;
decimals?: number;
duration?: number;
}
export function AnimatedNumber({
value,
prefix = '',
suffix = '',
decimals = 2,
duration = 500,
}: AnimatedNumberProps) {
const prevValue = useRef(value);
const { number } = useSpring({
from: { number: prevValue.current },
to: { number: value },
config: { duration },
});
useEffect(() => {
prevValue.current = value;
}, [value]);
return (
<animated.span className="tabular-nums">
{number.to((n) => `${prefix}${n.toFixed(decimals)}${suffix}`)}
</animated.span>
);
}
Usage
<AnimatedNumber value={price} prefix="$" decimals={2} />
<AnimatedNumber value={percentage} suffix="%" decimals={1} />
Pattern 2: Value with Flash Effect
<AnimatedNumber value={price} prefix="$" decimals={2} />
<AnimatedNumber value={percentage} suffix="%" decimals={1} />
Flash color on value change:
import { useEffect, useState, useRef } from 'react';
import { cn } from '@/lib/utils';
interface FlashingValueProps {
value: number;
formatter: (value: number) => string;
}
export function FlashingValue({ value, formatter }: FlashingValueProps) {
const [flash, setFlash] = useState<'up' | 'down' | null>(null);
const prevValue = useRef(value);
useEffect(() => {
if (value !== prevValue.current) {
setFlash(value > prevValue.current ? 'up' : 'down');
prevValue.current = value;
const timer = setTimeout(() => setFlash(null), 600);
return () => clearTimeout(timer);
}
}, [value]);
return (
<span
className={cn(
'transition-colors duration-600',
flash === 'up' && 'text-success',
flash === 'down' && 'text-destructive'
)}
>
{formatter(value)}
</span>
);
}
Pattern 3: Financial Number Formatting
// lib/formatters.ts
export function formatCurrency(
value: number,
options: {
currency?: string;
compact?: boolean;
decimals?: number;
} = {}
): string {
const { currency = 'USD', compact = false, decimals = 2 } = options;
if (compact && Math.abs(value) >= 1_000_000_000) {
return `$${(value / 1_000_000_000).toFixed(1)}B`;
}
if (compact && Math.abs(value) >= 1_000_000) {
return `$${(value / 1_000_000).toFixed(1)}M`;
}
if (compact && Math.abs(value) >= 1_000) {
return `$${(value / 1_000).toFixed(1)}K`;
}
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency,
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
}).format(value);
}
export function formatPercentage(
value: number,
options: { showSign?: boolean; decimals?: number } = {}
): string {
const { showSign = true, decimals = 2 } = options;
const sign = showSign && value > 0 ? '+' : '';
return `${sign}${value.toFixed(decimals)}%`;
}
export function formatNumber(
value: number,
options: { compact?: boolean; decimals?: number } = {}
): string {
const { compact = false, decimals = 0 } = options;
if (compact) {
return Intl.NumberFormat('en-US', {
notation: 'compact',
maximumFractionDigits: 1,
}).format(value);
}
return new Intl.NumberFormat('en-US', {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
}).format(value);
}
Pattern 4: Price Ticker Component
interface PriceTickerProps {
symbol: string;
price: number;
change24h: number;
changePercent24h: number;
}
export function PriceTicker({
symbol,
price,
change24h,
changePercent24h,
}: PriceTickerProps) {
const isPositive = changePercent24h >= 0;
return (
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
<div className="flex items-center gap-2">
<span className="font-display font-medium">{symbol}</span>
</div>
<div className="flex items-center gap-3">
<AnimatedNumber value={price} prefix="$" decimals={2} />
<span
className={cn(
'text-sm font-mono tabular-nums',
isPositive ? 'text-success' : 'text-destructive'
)}
>
{formatPercentage(changePercent24h)}
</span>
</div>
</div>
);
}
Pattern 5: Metric Card with Animation
interface MetricCardProps {
label: string;
value: number;
previousValue?: number;
format: 'currency' | 'percent' | 'number';
}
export function MetricCard({
label,
value,
previousValue,
format,
}: MetricCardProps) {
const formatValue = (v: number) => {
switch (format) {
case 'currency': return formatCurrency(v, { compact: true });
case 'percent': return formatPercentage(v);
case 'number': return formatNumber(v, { compact: true });
}
};
const change = previousValue ? ((value - previousValue) / previousValue) * 100 : null;
return (
<Surface layer="metric" className="p-4">
<div className="text-xs uppercase tracking-wider text-muted-foreground mb-1">
{label}
</div>
<div className="text-2xl font-bold font-mono tabular-nums">
<FlashingValue value={value} formatter={formatValue} />
</div>
{change !== null && (
<div className={cn(
'text-xs font-mono mt-1',
change >= 0 ? 'text-success' : 'text-destructive'
)}>
{formatPercentage(change)} from previous
</div>
)}
</Surface>
);
}
Pattern 6: CSS Value Flash Animation
@keyframes value-flash-up {
0% {
color: hsl(var(--success));
text-shadow: 0 0 8px hsl(var(--success) / 0.5);
}
100% {
color: inherit;
text-shadow: none;
}
}
@keyframes value-flash-down {
0% {
color: hsl(var(--destructive));
text-shadow: 0 0 8px hsl(var(--destructive) / 0.5);
}
100% {
color: inherit;
text-shadow: none;
}
}
.animate-flash-up {
animation: value-flash-up 0.6s ease-out;
}
.animate-flash-down {
animation: value-flash-down 0.6s ease-out;
}
Related Skills
- Meta-skill: ai/skills/meta/design-system-creation/ — Complete design system workflow
- financial-data-visualization — Chart theming and data visualization
- realtime-react-hooks — Real-time data hooks for live updates
NEVER Do
- Skip tabular-nums — Numbers will jump as they change
- Use linear animations — Spring/ease-out feels more natural
- Animate decimals rapidly — Too much motion is distracting
- Forget compact formatting — Large numbers need abbreviation
- Show raw floats — Always format with appropriate precision
- Flash on every render — Only flash on actual value changes
Typography for Numbers
.metric {
font-family: var(--font-mono);
font-variant-numeric: tabular-nums;
font-weight: 600;
letter-spacing: -0.02em;
}
.price-large {
font-size: 2rem;
font-weight: 800;
}
.percentage {
font-size: 0.875rem;
font-weight: 500;
}
// lib/formatters.ts
export function formatCurrency(
value: number,
options: {
currency?: string;
compact?: boolean;
decimals?: number;
} = {}
): string {
const { currency = 'USD', compact = false, decimals = 2 } = options;
if (compact && Math.abs(value) >= 1_000_000_000) {
return `$${(value / 1_000_000_000).toFixed(1)}B`;
}
if (compact && Math.abs(value) >= 1_000_000) {
return `$${(value / 1_000_000).toFixed(1)}M`;
}
if (compact && Math.abs(value) >= 1_000) {
return `$${(value / 1_000).toFixed(1)}K`;
}
return new Intl.NumberFormat('en-US', {
style: 'currency',
currency,
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
}).format(value);
}
export function formatPercentage(
value: number,
options: { showSign?: boolean; decimals?: number } = {}
): string {
const { showSign = true, decimals = 2 } = options;
const sign = showSign && value > 0 ? '+' : '';
return `${sign}${value.toFixed(decimals)}%`;
}
export function formatNumber(
value: number,
options: { compact?: boolean; decimals?: number } = {}
): string {
const { compact = false, decimals = 0 } = options;
if (compact) {
return Intl.NumberFormat('en-US', {
notation: 'compact',
maximumFractionDigits: 1,
}).format(value);
}
return new Intl.NumberFormat('en-US', {
minimumFractionDigits: decimals,
maximumFractionDigits: decimals,
}).format(value);
}
interface PriceTickerProps {
symbol: string;
price: number;
change24h: number;
changePercent24h: number;
}
export function PriceTicker({
symbol,
price,
change24h,
changePercent24h,
}: PriceTickerProps) {
const isPositive = changePercent24h >= 0;
return (
<div className="flex items-center justify-between p-3 rounded-lg bg-muted/50">
<div className="flex items-center gap-2">
<span className="font-display font-medium">{symbol}</span>
</div>
<div className="flex items-center gap-3">
<AnimatedNumber value={price} prefix="$" decimals={2} />
<span
className={cn(
'text-sm font-mono tabular-nums',
isPositive ? 'text-success' : 'text-destructive'
)}
>
{formatPercentage(changePercent24h)}
</span>
</div>
</div>
);
}
Pattern 5: Metric Card with Animation
interface MetricCardProps {
label: string;
value: number;
previousValue?: number;
format: 'currency' | 'percent' | 'number';
}
export function MetricCard({
label,
value,
previousValue,
format,
}: MetricCardProps) {
const formatValue = (v: number) => {
switch (format) {
case 'currency': return formatCurrency(v, { compact: true });
case 'percent': return formatPercentage(v);
case 'number': return formatNumber(v, { compact: true });
}
};
const change = previousValue ? ((value - previousValue) / previousValue) * 100 : null;
return (
<Surface layer="metric" className="p-4">
<div className="text-xs uppercase tracking-wider text-muted-foreground mb-1">
{label}
</div>
<div className="text-2xl font-bold font-mono tabular-nums">
<FlashingValue value={value} formatter={formatValue} />
</div>
{change !== null && (
<div className={cn(
'text-xs font-mono mt-1',
change >= 0 ? 'text-success' : 'text-destructive'
)}>
{formatPercentage(change)} from previous
</div>
)}
</Surface>
);
}
Pattern 6: CSS Value Flash Animation
@keyframes value-flash-up {
0% {
color: hsl(var(--success));
text-shadow: 0 0 8px hsl(var(--success) / 0.5);
}
100% {
color: inherit;
text-shadow: none;
}
}
@keyframes value-flash-down {
0% {
color: hsl(var(--destructive));
text-shadow: 0 0 8px hsl(var(--destructive) / 0.5);
}
100% {
color: inherit;
text-shadow: none;
}
}
.animate-flash-up {
animation: value-flash-up 0.6s ease-out;
}
.animate-flash-down {
animation: value-flash-down 0.6s ease-out;
}
Related Skills
- Meta-skill: ai/skills/meta/design-system-creation/ — Complete design system workflow
- financial-data-visualization — Chart theming and data visualization
- realtime-react-hooks — Real-time data hooks for live updates
NEVER Do
- Skip tabular-nums — Numbers will jump as they change
- Use linear animations — Spring/ease-out feels more natural
- Animate decimals rapidly — Too much motion is distracting
- Forget compact formatting — Large numbers need abbreviation
- Show raw floats — Always format with appropriate precision
- Flash on every render — Only flash on actual value changes
Typography for Numbers
.metric {
font-family: var(--font-mono);
font-variant-numeric: tabular-nums;
font-weight: 600;
letter-spacing: -0.02em;
}
.price-large {
font-size: 2rem;
font-weight: 800;
}
.percentage {
font-size: 0.875rem;
font-weight: 500;
}
interface MetricCardProps {
label: string;
value: number;
previousValue?: number;
format: 'currency' | 'percent' | 'number';
}
export function MetricCard({
label,
value,
previousValue,
format,
}: MetricCardProps) {
const formatValue = (v: number) => {
switch (format) {
case 'currency': return formatCurrency(v, { compact: true });
case 'percent': return formatPercentage(v);
case 'number': return formatNumber(v, { compact: true });
}
};
const change = previousValue ? ((value - previousValue) / previousValue) * 100 : null;
return (
<Surface layer="metric" className="p-4">
<div className="text-xs uppercase tracking-wider text-muted-foreground mb-1">
{label}
</div>
<div className="text-2xl font-bold font-mono tabular-nums">
<FlashingValue value={value} formatter={formatValue} />
</div>
{change !== null && (
<div className={cn(
'text-xs font-mono mt-1',
change >= 0 ? 'text-success' : 'text-destructive'
)}>
{formatPercentage(change)} from previous
</div>
)}
</Surface>
);
}
@keyframes value-flash-up {
0% {
color: hsl(var(--success));
text-shadow: 0 0 8px hsl(var(--success) / 0.5);
}
100% {
color: inherit;
text-shadow: none;
}
}
@keyframes value-flash-down {
0% {
color: hsl(var(--destructive));
text-shadow: 0 0 8px hsl(var(--destructive) / 0.5);
}
100% {
color: inherit;
text-shadow: none;
}
}
.animate-flash-up {
animation: value-flash-up 0.6s ease-out;
}
.animate-flash-down {
animation: value-flash-down 0.6s ease-out;
}
Related Skills
- Meta-skill: ai/skills/meta/design-system-creation/ — Complete design system workflow
- financial-data-visualization — Chart theming and data visualization
- realtime-react-hooks — Real-time data hooks for live updates
NEVER Do
- Skip tabular-nums — Numbers will jump as they change
- Use linear animations — Spring/ease-out feels more natural
- Animate decimals rapidly — Too much motion is distracting
- Forget compact formatting — Large numbers need abbreviation
- Show raw floats — Always format with appropriate precision
- Flash on every render — Only flash on actual value changes
Typography for Numbers
.metric {
font-family: var(--font-mono);
font-variant-numeric: tabular-nums;
font-weight: 600;
letter-spacing: -0.02em;
}
.price-large {
font-size: 2rem;
font-weight: 800;
}
.percentage {
font-size: 0.875rem;
font-weight: 500;
}
- Skip tabular-nums — Numbers will jump as they change
- Use linear animations — Spring/ease-out feels more natural
- Animate decimals rapidly — Too much motion is distracting
- Forget compact formatting — Large numbers need abbreviation
- Show raw floats — Always format with appropriate precision
- Flash on every render — Only flash on actual value changes
Typography for Numbers
.metric {
font-family: var(--font-mono);
font-variant-numeric: tabular-nums;
font-weight: 600;
letter-spacing: -0.02em;
}
.price-large {
font-size: 2rem;
font-weight: 800;
}
.percentage {
font-size: 0.875rem;
font-weight: 500;
}
.metric {
font-family: var(--font-mono);
font-variant-numeric: tabular-nums;
font-weight: 600;
letter-spacing: -0.02em;
}
.price-large {
font-size: 2rem;
font-weight: 800;
}
.percentage {
font-size: 0.875rem;
font-weight: 500;
}
正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。