GifproGifpro

Framer Motion Morphing Cards: AI Prompt & Code Example

CODE PREVIEW

エディタを読み込み中…
P

Prompt

Create an interactive card layout with Framer Motion where cards smoothly morph between different states on hover and click. Include spring animations, layout animations, and shared element transitions.

このインタラクティブなカードレイアウトは、ReactにおけるFramer Motionの強力なアニメーション機能を実演しています。実装では3つの主要な機能を紹介しています:

1. レイアウトアニメーション:カードをクリックすると、Framer Motionがlayoutプロップを使用して、グリッドから単一カラムレイアウトへの変更を自動的にアニメーション化します。手動のアニメーション定義は不要で、ライブラリが位置とサイズの遷移を自動的に処理します。

2. 共有要素トランジション:layoutIdプロップは、カード状態間のスムーズなモーフィング効果を作成します。カードの背景、タイトル、アイコンが展開/縮小時に視覚的な連続性を維持していることに注目してください。

3. スプリング物理演算:すべてのアニメーションは、自然で弾力のある動きのためにスプリング物理演算を使用しています。whileHoverプロップはインタラクティブなスケール効果を追加し、AnimatePresenceは説明テキストの表示/非表示アニメーションを処理します。

この実装は完全にレスポンシブで、Framer Motionが宣言型APIで複雑なアニメーションワークフローをどのように簡素化するかを示しています。

Prompt Overview

This prompt targets front-end developers and UI designers who want to build visually engaging card components using Framer Motion, the popular React animation library. By requesting spring animations, layout animations, and shared element transitions all in one go, it produces a polished, production-ready interaction pattern where cards smoothly morph between their default, hovered, and expanded states. This kind of component is ideal for portfolio sites, product showcases, dashboards, or any interface where surfacing more detail on demand improves the user experience.

To get the best results, run this prompt in a code-generation model such as GPT-4o or Claude 3.5 Sonnet, and paste the output directly into a Next.js or Vite React project with Framer Motion already installed. From there, you can experiment with variations — try swapping spring stiffness and damping values to feel snappier or more fluid, replace placeholder card content with real data, or extend the shared element transition to animate between a card grid and a full-screen detail view.

Was this prompt helpful?

Comments

Comments appear after moderation

この記事が役に立ったら投げ銭で応援

Apple Pay / Google Pay / カード (Visa/Mastercard/JCB/Amex) / Link / Alipay / WeChat Pay 対応 · Stripeで安全に決済

開発者が選ぶ最強ツール集

運営者が毎日使っているツール・ガジェット 6選

見る
Homeヘルプ