仕組み
The border is the root's padding showing two background layers: a pointer light over a conic gradient that a registered angle turns, with no spinning oversized element. Most of the conic is the plain border colour and one long arc carries the palette, so at rest the card is calm and its edge only quietly alive. One window listener, throttled to animation frames, writes where on the edge the pointer is closest and how near it is (0 to 1); the border, a blurred glow underneath and a faint wash inside all brighten together as the pointer approaches.
向いている場面
- The one recommended option among several, such as a plan or a template.
- A featured card that should invite the pointer without shouting.
向かない場面
- Every card in a grid: the highlight loses its meaning.
- Error or warning states: use a plain coloured border.
使い方
import { AnimatedBorderCard } from './AnimatedBorderCard.jsx'
export function RecommendedPlan() {
return (
<AnimatedBorderCard as="article" palette="aurora" speed={8} proximity={160}>
<div style={{ padding: 24 }}>
<h3>Studio</h3>
<p>For small teams shipping every week.</p>
</div>
</AnimatedBorderCard>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
children | ReactNode | — | Card content; give it its own padding. |
palette | 'aurora' | 'sunset' | 'mono' | 'aurora' | Colours of the travelling arc. |
speed | number | 8 | Seconds per full turn (minimum 1). |
borderWidth | number | 1.5 | Border thickness in px. |
proximity | number | 160 | Distance in px at which the pointer starts to light the border; 0 turns it off. |
glow | boolean | true | Soft coloured glow under the card. |
as | ElementType | 'div' | Root element. |
アクセシビリティ
- Purely decorative: the border, glow and pointer light carry no information, and the card renders its children unchanged.
- The pointer effect listens passively and only on devices that hover; keyboard and touch users see the turning border alone.
- Forced-colors mode draws a solid border in the text colour.
- Reduced motion stops the turn and parks the arc on the top-right edge; the pointer light still responds, without movement.
モーション
The arc turns linearly once every 8s (adjustable), which reads as a slow drift. The glow under the card eases between strengths over 360ms; the pointer light follows every animation frame.
プロジェクトに追加
Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。
AnimatedBorderCard.jsxanimated-border-card.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。







