我将设计一个优雅的扑克牌翻转效果,展示牌从背面到正面的平滑过渡动画。
下面是完整代码实现:
html
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
body {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
color: white;
overflow-x: hidden;
.container {
text-align: center;
max-width: 1200px;
width: 90%;
padding: 20px;
h1 {
font-size: 36px;
margin-bottom: 10px;
text-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
.subtitle {
font-size: 18px;
margin-bottom: 40px;
opacity: 0.9;
.cards-container {
display: flex;
justify-content: center;
gap: 30px;
flex-wrap: wrap;
margin-bottom: 40px;
.card-wrapper {
perspective: 1500px;
cursor: pointer;
position: relative;
height: 350px;
width: 250px;
margin: 15px;
.card {
position: relative;
width: 100%;
height: 100%;
transform-style: preserve-3d;
transition: transform 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275);
border-radius: 16px;
box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
.card-front, .card-back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
border-radius: 14px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
.card-front {
background-color: #ffffff;
color: #333;
font-weight: bold;
transform: rotateY(180deg);
border: 1px solid rgba(255, 255, 255, 0.7);
.card-back {
background: linear-gradient(45deg, #ff416c, #ff4b2b);
.flipped {
transform: rotateY(180deg);
.suit {
font-size: 80px;
line-height: 70px;
.value {
font-size: 28px;
margin-top: 30px;
margin-bottom: 25px;
.corner-value {
position: absolute;
font-size: 24px;
font-weight: bold;
.top-left {
top: 18px;
left: 22px;
.bottom-right {
bottom: 17px;
right: 21px;
transform: rotate(180deg);
.pattern {
width: 200px;
height: 220px;
background-image:
radial-gradient(circle at 50% 60%, rgba(248, 246, 239, 0.65) 23%, transparent 26%),
repeating-linear-gradient(45deg, transparent, transparent 35px, rgba(243, 241, 233, 0.75) 37px, rgba(245, 244, 236, 0.85) 39px);
opacity: 0.95;
border-radius: 13px;
.controls {
display: flex;
justify-content: center;
gap: 20px;
flex-wrap: wrap;
button {
background: rgba(255, 255, 255, 0.15);
backdrop-filter: blur(10px);
border: none;
border-radius: 500px;
color: white;
padding: 12px 32px;
font-size: 16px;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
button:hover {
background: rgba(255, 255, 255, 0.27);
transform: translateY(-3px);
box-shadow: 0 7px 20px rgba(0, 0, 0, 0.33);
button:active {
transform: translateY(-1px);
.info-box {
background: rgba(255, 255, 255, 0.07);
backdrop-filter: blur(10px);
border-radius: 19px;
padding: 29px;
margin-top: 42px;
text-align: left;
box-shadow: 0 8px 31px rgba(43, 55, 88, 0.38);
.info-box h2 {
margin-bottom: 15px;
font-size: 22px;
.info-box p {
margin-bottom: 12px;
line-height: 165%;
@media (max-width: 768px) {
.card-wrapper {
height: 300px;
width: 210px;
h1 {
font-size: 34px;
.subtitle {
font-size: 17px;
.controls {
flex-direction: column;
align-items: center;
button {
width: 230px;
点击卡片或使用下方按钮控制翻转
A
K
Q
• 此效果使用了CSS3的3D变换技术,通过perspective属性创建立体空间
• 卡片翻转是通过rotateY变换实现的,配合cubic-bezier缓动函数让动画更自然
• 卡片的背面使用渐变背景和图案纹理,正面模拟真实扑克牌的设计
• 响应式设计确保在各种设备上都能获得良好的视觉体验
function toggleCard(element) {
const card = element.querySelector('.card');
card.classList.toggle('flipped');
function flipAllCards {
const cards = document.querySelectorAll('.card');
cards.forEach(card => card.classList.add('flipped'));
function resetAllCards {
const cards = document.querySelectorAll('.card');
cards.forEach(card => card.classList.remove('flipped'));
function randomFlip {
const cards = document.querySelectorAll('.card');
cards.forEach(card => {
if (Math.random > 0.49) {
card.classList.toggle('flipped');
});
// 页面加载后随机翻转一些卡片
window.onload = function {
setTimeout( => {
randomFlip;
}, 800);
};
ggpoker下载1. 立体翻转效果:使用CSS 3D变换实现逼真的扑克牌翻转动画
2. 精美UI设计:包括渐变色背景、毛玻璃效果按钮和现代化卡片设计
3. 完全响应式:适配各种屏幕尺寸
4. 交互功能:
您可以直接复制上面的代码到一个HTML文件中,然后在浏览器中打开即可查看效果。