Created
November 5, 2023 10:01
-
-
Save Mif2006/6e672d296a0f46507d7423e62beb6562 to your computer and use it in GitHub Desktop.
Card flip
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
import { motion } from "framer-motion"; | |
import SpaceCity from "../assets/SpaceCity.jpg"; | |
import SpaceCity1 from "../assets/SpaceCity1.jpg"; | |
const CardFlip = () => { | |
const [isFlipped, setIsFlipped] = useState(false); | |
const [isAnimating, setIsAnimating] = useState(false); | |
function handleFlip() { | |
if (!isAnimating) { | |
setIsFlipped(!isFlipped); | |
setIsAnimating(true); | |
} | |
} | |
return ( | |
<div className="flex items-center justify-center bg-black h-[800px] cursor-pointer"> | |
<div | |
className="flip-card w-[600px] h-[360px] rounded-md" | |
onClick={handleFlip} | |
> | |
<motion.div | |
className="flip-card-inner w-[100%] h-[100%]" | |
initial={false} | |
animate={{ rotateY: isFlipped ? 180 : 360 }} | |
transition={{ duration: 0.6, animationDirection: "normal" }} | |
onAnimationComplete={() => setIsAnimating(false)} | |
> | |
<div | |
className="flip-card-front w-[100%] h-[100%] bg-cover border-[1px] text-white rounded-lg p-4" | |
style={{ backgroundImage: `url(${SpaceCity})` }} | |
> | |
<h1 className="text-2xl font-bold/">Sky</h1> | |
<p>Live on top of the world</p> | |
</div> | |
<div | |
className="flip-card-back w-[100%] h-[100%] bg-cover border-[1px] text-white rounded-lg p-4" | |
style={{ backgroundImage: `url(${SpaceCity1})` }} | |
> | |
<h1 className="text-2xl font-bold/">Earth</h1> | |
<p>Or in the maze of the city</p> | |
</div> | |
</motion.div> | |
</div> | |
</div> | |
); | |
}; | |
export default CardFlip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tailwind base; | |
@tailwind components; | |
@tailwind utilities; | |
.flip-card { | |
perspective: 1000px; | |
} | |
.flip-card-inner { | |
transition: transform 0.6s; | |
transform-style: preserve-3d; | |
} | |
.flip-card-front, | |
.flip-card-back { | |
position: absolute; | |
backface-visibility: hidden; | |
} | |
.flip-card-back { | |
transform: rotateY(180deg); | |
} | |
@keyframes rotateGradient { | |
0% { | |
background-position: 0% 0%; | |
} | |
100% { | |
background-position: 100% 100%; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment