🥶 Playing Cards
The PlayingCards component is an interactive React component that creates a stunning stacked card effect with smooth animations. Built with Framer Motion, it displays multiple images in a cascading stack that dynamically spreads out on hover. Each card features a subtle rotation and offset, creating a realistic playing card stack effect. The component includes smooth transitions, opacity gradients, and responsive design, making it perfect for showcasing image galleries, portfolios, or product displays. With its elegant hover animations and professional styling, it adds a touch of sophistication to any web application. The component is fully responsive, supports Next.js Image optimization, and can be easily integrated into any React project
Preview
Top travel destinations
Follow below steps 👇🏻
Component
Create a file playing-cards.tsx in your components folder and paste this code
1'use client';23import React, { useState } from 'react';4import Image from 'next/image';5import { motion } from 'framer-motion';67const PlayingCards = ({ images }: { images: string[] }) => {8const [isHovered, setIsHovered] = useState(false);910return (11<div12onMouseEnter={() => setIsHovered(true)}13onMouseLeave={() => setIsHovered(false)}14className="relative h-[300px] max-w-[300px] w-full mx-auto p-5 rounded-lg transition-all duration-300 hover:translate-x-[10px]"15>16{images.map((image, i) => {17return (18<motion.div19key={i}20className="absolute top-0 left-0 w-full h-full border border-white/40 rounded-lg overflow-hidden"21initial={{22left: i * 10,23rotate: (i - 1) * 324}}25animate={{26left: isHovered ? (i - 1) * 50 : i * 10,27rotate: isHovered ? (i - 1) * 10 : (i - 1) * 328}}29transition={{ duration: 0.3 }}30style={{31zIndex: images.length - i,32transformOrigin: 'center center',33boxShadow: '0 4px 8px rgba(0,0,0,0.1)',34opacity: 1 - i * 0.2,35width: 'calc(100% - 16px)',36height: 'calc(100% - 16px)'37}}38>39<Image40src={image}41alt={`Stacked image ${i + 1}`}42width={1000}43height={1000}44className="w-full h-full object-cover"45/>46</motion.div>47);48})}49</div>50);51};5253export default PlayingCards;
Usage
1<PlayingCards2images={[3'https://images.unsplash.com/photo-1744619438376-30bfc6c4666c?q=80&w=3000&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D',4'https://9ygf064mjl.ufs.sh/f/CFdX3UwvlhucsXH4v6uEYbmGZX2qF6LkRCBayrh9Wi75Icon',5'https://9ygf064mjl.ufs.sh/f/CFdX3UwvlhucppBTiobPgpLht7umOSknV5ciMBWqjAavrFZw'6]}7/>
⭐️ Got a question or feedback?
Feel free to reach out!