【3D卡片切换】基于jquery实现3D堆叠卡片切换效果(附完整源码)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D Card Flip Effect</title>
<style>
body, html {
height: 100%;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
perspective: 1000px;
}
.card {
width: 300px;
height: 400px;
background-color: #fff;
border: 1px solid #ccc;
cursor: pointer;
position: relative;
transition: transform 1s;
transform-style: preserve-3d;
}
.card.flip {
transform: rotateY(180deg);
}
.card .face {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.card .face.back {
display: flex;
align-items: center;
justify-content: center;
background-color: #f0f0f0;
transform: rotateY(180deg);
}
.card .face.front {
background-color: #bbb;
}
</style>
</head>
<body>
<div class="card">
<div class="face front">Front</div>
<div class="face back">Back</div>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('.card').click(function() {
$(this).toggleClass('flip');
});
});
</script>
</body>
</html>
这段代码实现了一个简单的3D卡片切换效果。用户点击卡片时,卡片会旋转180度显示另一面。使用了jQuery来处理点击事件和类的切换。这个例子展示了如何结合HTML、CSS和JavaScript实现动态界面效果。
评论已关闭