<!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>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
background: linear-gradient(to bottom, #ffcce6, #ffe6f2);
min-height: 100vh;
overflow: hidden;
font-family: 'Arial', sans-serif;
}
.container {
position: relative;
width: 100%;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 10;
text-align: center;
padding: 20px;
}
h1 {
font-size: 3rem;
margin-bottom: 20px;
color: #ff1493;
text-shadow: 0 0 10px rgba(255, 255, 255, 0.7);
}
p {
font-size: 1.2rem;
margin-bottom: 30px;
color: #d63384;
max-width: 600px;
line-height: 1.6;
}
.link-btn {
display: inline-block;
padding: 12px 30px;
background: linear-gradient(45deg, #ff1493, #ff69b4);
color: white;
text-decoration: none;
border-radius: 50px;
font-weight: bold;
font-size: 1.1rem;
transition: all 0.3s ease;
box-shadow: 0 5px 15px rgba(255, 20, 147, 0.4);
margin-top: 20px;
}
.link-btn:hover {
transform: translateY(-3px);
box-shadow: 0 8px 25px rgba(255, 20, 147, 0.6);
}
.footer {
position: fixed;
bottom: 20px;
width: 100%;
text-align: center;
color: #d63384;
font-size: 0.9rem;
z-index: 10;
}
.footer a {
color: #ff1493;
text-decoration: none;
font-weight: bold;
}
.footer a:hover {
text-decoration: underline;
}
/* 樱花样式 */
.sakura {
position: absolute;
pointer-events: none;
user-select: none;
z-index: 1;
animation: sakura-fall linear infinite;
opacity: 0;
}
@keyframes sakura-fall {
0% {
transform: translateY(-10vh) rotate(0deg);
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
transform: translateY(110vh) rotate(360deg);
opacity: 0;
}
}
/* 点击樱花样式 */
.click-sakura {
position: absolute;
pointer-events: none;
transform: translate(-50%, -50%);
animation: sakura-float 2s ease-out forwards;
opacity: 0.8;
z-index: 5;
}
@keyframes sakura-float {
0% {
transform: translate(-50%, -50%) scale(0.5);
opacity: 1;
}
100% {
transform: translate(-50%, -150%) scale(1.2);
opacity: 0;
}
}
</style>
</head>
<body>
<div class="container">
<h1>樱花飘落特效</h1>
<p>欣赏美丽的樱花飘落效果,点击页面任意位置还会出现额外的樱花绽放!</p>
</div>
<div class="footer">
</div>
<script>
// 樱花类型
const sakuraTypes = ['🌸', '💮', '🏵️', '🌺', '🌼'];
// 创建飘落樱花
function createFallingSakura() {
const sakuraCount = 50;
for (let i = 0; i < sakuraCount; i++) {
const sakura = document.createElement('div');
sakura.className = 'sakura';
// 随机选择樱花类型
const typeIndex = Math.floor(Math.random() * sakuraTypes.length);
sakura.textContent = sakuraTypes[typeIndex];
// 随机大小
const size = Math.random() * 25 + 15;
sakura.style.fontSize = `${size}px`;
// 随机位置
sakura.style.left = `${Math.random() * 100}%`;
// 随机动画时间和延迟
const duration = Math.random() * 10 + 10;
sakura.style.animationDuration = `${duration}s`;
sakura.style.animationDelay = `${Math.random() * 10}s`;
// 随机透明度
sakura.style.opacity = Math.random() * 0.7 + 0.3;
document.body.appendChild(sakura);
}
}
// 创建点击樱花
function createClickSakura(x, y) {
const sakura = document.createElement('div');
sakura.className = 'click-sakura';
// 随机选择樱花类型
const typeIndex = Math.floor(Math.random() * sakuraTypes.length);
sakura.textContent = sakuraTypes[typeIndex];
// 随机大小
const size = Math.random() * 30 + 20;
sakura.style.fontSize = `${size}px`;
// 随机颜色变化
const hue = Math.floor(Math.random() * 60) + 320; // 粉色系
sakura.style.color = `hsl(${hue}, 100%, 80%)`;
// 设置位置
sakura.style.left = `${x}px`;
sakura.style.top = `${y}px`;
document.body.appendChild(sakura);
// 动画结束后移除
setTimeout(() => {
sakura.remove();
}, 2000);
}
// 初始化樱花特效
window.addEventListener('load', () => {
createFallingSakura();
// 点击创建樱花
document.addEventListener('click', (e) => {
// 创建多个樱花
for (let i = 0; i < 5; i++) {
// 随机偏移
const offsetX = (Math.random() - 0.5) * 100;
const offsetY = (Math.random() - 0.5) * 100;
createClickSakura(e.clientX + offsetX, e.clientY + offsetY);
}
});
});
</script>
</body>
</html>
3436

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



