<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>纯CSS3绘制火龙果动画特效</title>
<style>
body {
margin: 0;
padding: 0;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
background: linear-gradient(135deg, #f5f7fa, #c3cfe2);
overflow: hidden;
font-family: Arial, sans-serif;
}
.dragon-fruit {
position: relative;
width: 200px;
height: 300px;
animation: float 3s ease-in-out infinite;
}
.fruit-body {
position: absolute;
width: 100%;
height: 100%;
background: #ff4d6d;
border-radius: 100px 100px 150px 150px;
box-shadow:
inset -10px -10px 30px rgba(0,0,0,0.2),
inset 10px 10px 30px rgba(255,255,255,0.3);
}
.leaf {
position: absolute;
width: 30px;
height: 80px;
background: #4caf50;
border-radius: 15px;
top: -40px;
transform-origin: bottom center;
}
.leaf:nth-child(1) {
left: 50%;
transform: translateX(-50%) rotate(0deg);
animation: leaf-sway 3s ease-in-out infinite;
}
.leaf:nth-child(2) {
left: 30%;
transform: rotate(-20deg);
animation: leaf-sway 3.5s ease-in-out infinite reverse;
}
.leaf:nth-child(3) {
right: 30%;
transform: rotate(20deg);
animation: leaf-sway 4s ease-in-out infinite;
}
.scale {
position: absolute;
width: 20px;
height: 20px;
background: rgba(255,255,255,0.3);
border-radius: 50%;
border: 2px solid rgba(255,255,255,0.5);
animation: scale-pulse 2s infinite alternate;
}
.title {
position: absolute;
top: 50px;
color: #ff4d6d;
font-size: 28px;
text-shadow: 0 2px 5px rgba(0,0,0,0.1);
}
.link {
position: absolute;
bottom: 20px;
right: 20px;
color: #ff4d6d;
font-size: 14px;
text-decoration: none;
font-weight: bold;
}
@keyframes float {
0%, 100% { transform: translateY(0); }
50% { transform: translateY(-20px); }
}
@keyframes leaf-sway {
0%, 100% { transform: rotate(0deg); }
50% { transform: rotate(10deg); }
}
@keyframes scale-pulse {
0% { transform: scale(0.8); opacity: 0.7; }
100% { transform: scale(1.2); opacity: 1; }
}
</style>
</head>
<body>
<h1 class="title">火龙果动画特效</h1>
<div class="dragon-fruit">
<div class="fruit-body" id="fruit-body">
<!-- 火龙果鳞片将通过JS添加 -->
</div>
<div class="leaf"></div>
<div class="leaf"></div>
<div class="leaf"></div>
</div>
<script>
// 添加火龙果鳞片
const fruitBody = document.getElementById('fruit-body');
const scalesCount = 30;
for (let i = 0; i < scalesCount; i++) {
const scale = document.createElement('div');
scale.className = 'scale';
// 随机位置
const angle = Math.random() * Math.PI * 2;
const radiusX = 80 + Math.random() * 20;
const radiusY = 120 + Math.random() * 30;
const x = 100 + Math.cos(angle) * radiusX;
const y = 150 + Math.sin(angle) * radiusY;
scale.style.left = `${x}px`;
scale.style.top = `${y}px`;
// 随机动画延迟
scale.style.animationDelay = `${Math.random() * 2}s`;
// 随机大小
const size = 10 + Math.random() * 10;
scale.style.width = `${size}px`;
scale.style.height = `${size}px`;
fruitBody.appendChild(scale);
}
</script>
</body>
</html>
4024

被折叠的 条评论
为什么被折叠?



