<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>彼岸花瓣掉落特效</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background: #000;
height: 100vh;
font-family: Arial, sans-serif;
}
.petal {
position: absolute;
background-size: contain;
background-repeat: no-repeat;
opacity: 0.7;
animation: falling linear infinite;
z-index: 1;
}
@keyframes falling {
0% {
transform: translate(0, -10vh) rotate(0deg);
opacity: 0;
}
10% {
opacity: 0.7;
}
90% {
opacity: 0.7;
}
100% {
transform: translate(var(--end-x), 100vh) rotate(360deg);
opacity: 0;
}
}
.content {
position: relative;
z-index: 2;
color: white;
text-align: center;
padding-top: 20vh;
}
h1 {
font-size: 3em;
text-shadow: 0 0 10px #ff00aa;
}
.link {
margin-top: 30px;
}
a {
color: #ff99cc;
text-decoration: none;
font-size: 1.2em;
transition: color 0.3s;
}
a:hover {
color: #ff00aa;
text-shadow: 0 0 5px #ff00aa;
}
</style>
</head>
<body>
<div class="content">
<h1>彼岸花开</h1>
<p>花瓣飘落,思念永存</p>
</div>
<script>
// 创建花瓣
function createPetals() {
const colors = [
'rgba(255, 0, 170, 0.7)', // 粉红
'rgba(255, 100, 200, 0.7)', // 浅粉
'rgba(200, 0, 120, 0.7)', // 深粉
'rgba(255, 50, 150, 0.7)' // 中粉
];
const shapes = [
'M20,0 C40,40 0,40 20,60 C40,40 0,40 20,0', // 心形花瓣
'M20,0 C30,20 10,20 20,40 C30,20 10,20 20,0', // 窄花瓣
'M20,0 C40,10 0,10 20,30 C40,10 0,10 20,0', // 宽花瓣
'M20,0 C35,15 5,15 20,30 C35,15 5,15 20,0' // 椭圆花瓣
];
for (let i = 0; i < 50; i++) {
setTimeout(() => {
const petal = document.createElement('div');
petal.className = 'petal';
// 随机大小
const size = Math.random() * 20 + 10;
// 随机颜色和形状
const color = colors[Math.floor(Math.random() * colors.length)];
const shape = shapes[Math.floor(Math.random() * shapes.length)];
// 创建SVG花瓣
petal.innerHTML = `
<svg width="${size}" height="${size}" viewBox="0 0 40 60">
<path d="${shape}" fill="${color}" />
</svg>
`;
// 随机起始位置
const startX = Math.random() * 100;
petal.style.left = `${startX}vw`;
// 随机结束位置偏移
const endX = (Math.random() - 0.5) * 20;
petal.style.setProperty('--end-x', `${endX}vw`);
// 随机动画时长
const duration = Math.random() * 10 + 10;
petal.style.animationDuration = `${duration}s`;
// 随机延迟
petal.style.animationDelay = `${Math.random() * 10}s`;
document.body.appendChild(petal);
}, i * 300);
}
}
// 页面加载后创建花瓣
window.addEventListener('load', createPetals);
</script>
</body>
</html>
3648

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



