3d-animations
Expert knowledge for CSS/JS-based 3D animations - perspective transforms, depth effects, card flips, cube rotations, and parallax depth without WebGL.
What this skill does
# 3D Animations Skill
Expert knowledge for CSS/JS-based 3D animations - perspective transforms, depth effects, card flips, cube rotations, and parallax depth without WebGL.
## When to Use
Activate this skill when:
- User wants 3D flip cards
- Creating perspective-based animations
- Building parallax depth effects
- Need rotating cubes or 3D objects
- Creating tilt-on-hover effects
- Building 3D carousels
## File Patterns
- `**/*.tsx` with 3D transform components
- `**/components/*3D*.tsx`
- `**/components/*Flip*.tsx`
- `**/components/*Tilt*.tsx`
## Core Concepts
### Perspective
```css
/* Parent container needs perspective */
.perspective-container {
perspective: 1000px;
perspective-origin: center;
}
/* Child can now use 3D transforms */
.card-3d {
transform-style: preserve-3d;
transform: rotateY(45deg);
}
```
## 3D Animation Types
### 1. 3D Flip Cards
#### Basic Flip Card
```tsx
import { motion } from 'framer-motion';
import { useState } from 'react';
interface FlipCardProps {
front: React.ReactNode;
back: React.ReactNode;
}
export function FlipCard({ front, back }: FlipCardProps) {
const [isFlipped, setIsFlipped] = useState(false);
return (
<div
className="relative w-64 h-80 cursor-pointer"
style={{ perspective: '1000px' }}
onClick={() => setIsFlipped(!isFlipped)}
>
<motion.div
className="w-full h-full relative"
style={{ transformStyle: 'preserve-3d' }}
animate={{ rotateY: isFlipped ? 180 : 0 }}
transition={{ duration: 0.6, type: 'spring', stiffness: 100 }}
>
{/* Front */}
<div
className="absolute inset-0 bg-gradient-to-br from-purple-500 to-pink-500 rounded-xl p-6 flex items-center justify-center"
style={{ backfaceVisibility: 'hidden' }}
>
{front}
</div>
{/* Back */}
<div
className="absolute inset-0 bg-gradient-to-br from-blue-500 to-cyan-500 rounded-xl p-6 flex items-center justify-center"
style={{ backfaceVisibility: 'hidden', transform: 'rotateY(180deg)' }}
>
{back}
</div>
</motion.div>
</div>
);
}
```
#### Flip Card on Hover
```tsx
export function HoverFlipCard({ front, back }: FlipCardProps) {
return (
<motion.div
className="relative w-64 h-80 cursor-pointer group"
style={{ perspective: '1000px' }}
whileHover="flipped"
initial="initial"
>
<motion.div
className="w-full h-full relative"
style={{ transformStyle: 'preserve-3d' }}
variants={{
initial: { rotateY: 0 },
flipped: { rotateY: 180 },
}}
transition={{ duration: 0.6 }}
>
<div
className="absolute inset-0 bg-white rounded-xl shadow-xl p-6"
style={{ backfaceVisibility: 'hidden' }}
>
{front}
</div>
<div
className="absolute inset-0 bg-slate-900 text-white rounded-xl shadow-xl p-6"
style={{ backfaceVisibility: 'hidden', transform: 'rotateY(180deg)' }}
>
{back}
</div>
</motion.div>
</motion.div>
);
}
```
### 2. Tilt Effects
#### Tilt on Hover
```tsx
import { motion, useMotionValue, useSpring, useTransform } from 'framer-motion';
export function TiltCard({ children }: { children: React.ReactNode }) {
const x = useMotionValue(0);
const y = useMotionValue(0);
const rotateX = useSpring(useTransform(y, [-0.5, 0.5], [15, -15]), {
stiffness: 300,
damping: 30,
});
const rotateY = useSpring(useTransform(x, [-0.5, 0.5], [-15, 15]), {
stiffness: 300,
damping: 30,
});
const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
const rect = e.currentTarget.getBoundingClientRect();
const centerX = rect.left + rect.width / 2;
const centerY = rect.top + rect.height / 2;
x.set((e.clientX - centerX) / rect.width);
y.set((e.clientY - centerY) / rect.height);
};
const handleMouseLeave = () => {
x.set(0);
y.set(0);
};
return (
<motion.div
className="relative bg-white rounded-xl shadow-xl p-6"
style={{
perspective: '1000px',
rotateX,
rotateY,
transformStyle: 'preserve-3d',
}}
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
>
<div style={{ transform: 'translateZ(50px)' }}>{children}</div>
</motion.div>
);
}
```
#### Tilt with Shine Effect
```tsx
export function ShinyTiltCard({ children }: { children: React.ReactNode }) {
const x = useMotionValue(0);
const y = useMotionValue(0);
const rotateX = useSpring(useTransform(y, [-0.5, 0.5], [10, -10]));
const rotateY = useSpring(useTransform(x, [-0.5, 0.5], [-10, 10]));
const shineX = useTransform(x, [-0.5, 0.5], ['0%', '100%']);
const shineY = useTransform(y, [-0.5, 0.5], ['0%', '100%']);
const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
const rect = e.currentTarget.getBoundingClientRect();
x.set((e.clientX - rect.left) / rect.width - 0.5);
y.set((e.clientY - rect.top) / rect.height - 0.5);
};
return (
<motion.div
className="relative overflow-hidden rounded-xl bg-gradient-to-br from-purple-500 to-pink-500 p-8"
style={{ rotateX, rotateY, transformStyle: 'preserve-3d' }}
onMouseMove={handleMouseMove}
onMouseLeave={() => { x.set(0); y.set(0); }}
>
{/* Shine overlay */}
<motion.div
className="absolute inset-0 pointer-events-none"
style={{
background: `radial-gradient(circle at ${shineX} ${shineY}, rgba(255,255,255,0.3) 0%, transparent 50%)`,
}}
/>
<div style={{ transform: 'translateZ(30px)' }}>{children}</div>
</motion.div>
);
}
```
### 3. 3D Rotating Cube
#### CSS Cube
```tsx
export function RotatingCube({ faces }: { faces: React.ReactNode[] }) {
const [rotation, setRotation] = useState({ x: 0, y: 0 });
useEffect(() => {
const interval = setInterval(() => {
setRotation((prev) => ({
x: prev.x + 0.5,
y: prev.y + 0.5,
}));
}, 16);
return () => clearInterval(interval);
}, []);
const size = 150;
return (
<div
className="relative"
style={{
width: size,
height: size,
perspective: '600px',
}}
>
<div
className="w-full h-full relative"
style={{
transformStyle: 'preserve-3d',
transform: `rotateX(${rotation.x}deg) rotateY(${rotation.y}deg)`,
}}
>
{/* Front */}
<div
className="absolute bg-purple-500/90 border border-purple-300"
style={{
width: size,
height: size,
transform: `translateZ(${size / 2}px)`,
}}
>
{faces[0]}
</div>
{/* Back */}
<div
className="absolute bg-blue-500/90 border border-blue-300"
style={{
width: size,
height: size,
transform: `rotateY(180deg) translateZ(${size / 2}px)`,
}}
>
{faces[1]}
</div>
{/* Left */}
<div
className="absolute bg-green-500/90 border border-green-300"
style={{
width: size,
height: size,
transform: `rotateY(-90deg) translateZ(${size / 2}px)`,
}}
>
{faces[2]}
</div>
{/* Right */}
<div
className="absolute bg-yellow-500/90 border border-yellow-300"
style={{
width: size,
height: size,
transform: `rotateY(90deg) translateZ(${size / 2}px)`,
}}
>
{faces[3]}
</div>
{/* Top */}
<div
className="absolute bg-pink-500/90 border border-pink-300"
style={{
width: size,
height: size,
transform: `rotateX(90deg) translateZ(${size / 2}px)`,
Related in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.