HTML 3D跳動的心代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>3D Heart Jumping Effect</title>
<style>
body {
background-color: #f5f5f5;
}
.heart-container {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.heart {
position: relative;
width: 50px;
height: 50px;
transform: translateZ(-25px);
transform-style: preserve-3d;
animation: beat 1s infinite ease-in-out;
}
.heart:after,
.heart:before {
position: absolute;
content: "";
width: inherit;
height: inherit;
border-radius: 25px 25px 0 0;
background-color: #ff4965;
transform: rotate(45deg);
}
.heart:after {
transform: rotate(90deg);
}
@keyframes beat {
0% {
transform: translateZ(-25px);
}
50% {
transform: translateZ(-10px);
}
100% {
transform: translateZ(-25px);
}
}
</style>
</head>
<body>
<div class="heart-container">
<div class="heart"></div>
</div>
</body>
</html>
以上即為HTML 3D跳動的心代碼。實現(xiàn)效果為一個3D的心形圖案跳動在頁面中心。主要使用了CSS3的transform和transform-style來實現(xiàn)3D效果,同時使用了animation來實現(xiàn)跳動動畫效果。在HTML中只需添加一個div元素,然后為其添加heart和heart-container兩個類名即可。
上一篇saber vue