本文へ移動
日本語
「3D チルトカード」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

注目してほしい一枚だけに動きをつけましょう。

ポインタを重ねると、カードがその方向に傾きます。手前の層が浮かび、光が動きを追います。ポインタを離すと各層が元の位置に戻ります。

実装の詳細

外側の要素に perspective を設定し、変形させずに寸法を測ることで角度の揺れを防ぎます。内側のカードを回転・拡縮し、requestAnimationFrame で更新をまとめます。入りは 320ms、追従は 120ms、復帰は 700ms。ホバー時のみ translateZ で層を浮かせ、2 倍の大きさの放射状のハイライトを transform で移動します。

向いている場面

  • 商品のメイン画像商品写真や会員カードに奥行きを持たせます。
  • 商品の紹介枠背景から商品名と価格を浮かせて区別します。
  • 報酬の演出新しく手に入れたカードに実物らしい厚みを感じさせます。

向かない場面

  • 高密度な一覧多数のカードが一斉に傾かないよう、軽く浮かせる程度にします。
  • フォームや小さなボタン操作対象を固定し、正確にクリックできるようにします。
  • タッチ画面タッチでは傾きません。静止したまま情報が伝わる構成にします。

使い方

import { TiltCard, TiltLayer } from './TiltCard.jsx'

export function TripCard() {
  return (
    <TiltCard maxTilt={12} style={{ width: 300 }}>
      {/* The card face; round its corners with border-radius: inherit */}
      <div className="trip-face">
        <TiltLayer depth={18}>Skyline Air</TiltLayer>
        <TiltLayer depth={30}>
          <h3>Lisbon, 3 nights</h3>
        </TiltLayer>
        {/* A data-depth attribute works too */}
        <p data-depth="36">$680</p>
      </div>
    </TiltCard>
  )
}

プロパティ

プロパティ型既定値説明
maxTiltnumber12Maximum tilt angle in degrees, reached when the pointer is at the card edge.
glarebooleantrueShows the glare that follows the pointer.
glareOpacitynumber0.35Maximum glare opacity, 0 to 1.
scalenumber1.03Scale on hover; 1 means no scaling.
perspectivenumber900Perspective distance in px; smaller values look more dramatic.
childrenReactNode—The card face. The card has no background; its radius comes from --ds-tilt-radius (default 24px), so faces should use border-radius: inherit.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root <div>; set the width with style or className.
TiltLayer.depthnumber24How far a parallax layer floats, in px. Or put data-depth="number" on any child.

アクセシビリティ

  • When an element inside the card has keyboard focus, the card levels out and the glare hides, so focus rings and text stay clear.
  • With reduced motion enabled it does not tilt or float at all.
  • It reacts to mouse and pen only, not touch.
  • The glare layer is aria-hidden.

モーション

Enter 320ms ease-out; track 120ms ease-out; leave 700ms spring; layers float 360ms ease-out; glare in 240ms, out 360ms; shadow 360ms.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

TiltCard.jsxtilt-card.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

カード
「動く枠線カード」は Pro に含まれます。解除するとプレビューが表示されます。
「ビームボーダー」は Pro に含まれます。解除するとプレビューが表示されます。
「カード詳細とロック」は Pro に含まれます。解除するとプレビューが表示されます。