I’m diving into the world of CSS animation and attempting to replicate the card shuffling animation seen: https://go.topcreditcardfinder.com/
Here’s a glimpse of what I’ve achieved so far:
https://youtu.be/GDIJ2K22cnY
I’ve managed to achieve the basic movement, but I’m struggling with improving the translation and relative movement for each card. My goal is to refine the animation for a smoother and more realistic card shuffling effect.
My cards are moving but the animation is sudden and is not creating a cyclic shuffle animation like what i am expecting. What I maybe doing wrong here?
Here’s the code that I have written:
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="card-container">
<div class="card">
<img src="./assets/Cart Geometric 2.png" alt="Card 1">
</div>
<div class="card">
<img src="./assets/Cart Geometric 5.png" alt="Card 2">
</div>
<div class="card">
<img src="./assets/Cart Geometric 8.png" alt="Card 3">
</div>
</div>
</body>
</html>
CSS:
body {
font-family: 'HelveticaNeue', sans-serif;
margin: 0;
display: flex;
justify-content: flex-end;
align-items: center;
height: 100vh;
background: url('./assets/Vector 1.png') center/cover no-repeat , linear-gradient(180deg, #DBE4ED 100%, #BABABA 100%) ;
}
.container {
display: flex;
flex-direction: column;
align-items: center;
}
.card-container {
position: relative;
perspective: 1000px;
width: 300px;
height: 200px;
}
.card {
position: absolute;
width: 100%;
height: 100%;
transform-style: preserve-3d;
animation: rotateCard 6s linear infinite;
}
@keyframes rotateCard {
20% {
transform: rotate(4deg) translateY(-10px);
z-index: 3;
}
40%, 100% {
transform: rotate(-4deg) translateY(10px);
z-index: 2;
}
0%, 60%, 80% {
transform: scale(1) translateY(0);
z-index: 1;
}
}
.card:nth-child(2) { animation-delay: 2s; }
.card:nth-child(3) { animation-delay: 4s; }
.card img {
width: 100%;
height: 100%;
object-fit: cover;
border-radius: 10px;
margin-right: 170px;
}
2
Answers
I think this page will help you : https://www.w3schools.com/css/css3_transitions.asp
You can do a transition with each card moving, fading to opacity: 0 & doing illusion it passed under the other card.
I’ve recreated the animation at the link with just CSS here:
The percentages and time values are based on these calculations:
If you want to adjust any timings you’ll need to recalculate using the same method.