<!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 {
overflow: hidden;
background: linear-gradient(to bottom, #87CEEB, #1E90FF);
font-family: 'Arial', sans-serif;
height: 100vh;
position: relative;
}
.forest-scene {
position: absolute;
width: 100%;
height: 100%;
}
.tree {
position: absolute;
bottom: 0;
}
.tree-1 {
left: 10%;
height: 300px;
width: 150px;
background: linear-gradient(to right, #2E8B57, #3CB371);
clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
}
.tree-2 {
left: 30%;
height: 400px;
width: 200px;
background: linear-gradient(to right, #228B22, #32CD32);
clip-path: polygon(50% 0%, 20% 50%, 0% 100%, 100% 100%, 80% 50%);
}
.tree-3 {
right: 20%;
height: 350px;
width: 180px;
background: linear-gradient(to right, #006400, #008000);
clip-path: polygon(50% 0%, 0% 100%, 25% 100%, 50% 50%, 75% 100%, 100% 100%);
}
.ground {
position: absolute;
bottom: 0;
width: 100%;
height: 100px;
background: linear-gradient(to right, #8B4513, #A0522D);
}
.butterfly {
position: absolute;
width: 40px;
height: 40px;
animation: fly linear infinite;
z-index: 10;
}
.butterfly .left-wing {
position: absolute;
width: 20px;
height: 30px;
background: linear-gradient(to bottom, #FFD700, #FFA500);
border-radius: 100% 0 100% 0;
transform-origin: right center;
animation: flapLeft 0.2s ease-in-out infinite alternate;
}
.butterfly .right-wing {
position: absolute;
width: 20px;
height: 30px;
left: 20px;
background: linear-gradient(to bottom, #FF6347, #FF4500);
border-radius: 0 100% 0 100%;
transform-origin: left center;
animation: flapRight 0.2s ease-in-out infinite alternate;
}
.butterfly .body {
position: absolute;
width: 4px;
height: 30px;
left: 18px;
top: 5px;
background: #333;
border-radius: 2px;
}
.sun {
position: absolute;
width: 100px;
height: 100px;
background: radial-gradient(circle, #FFD700, #FFA500);
border-radius: 50%;
top: 50px;
right: 100px;
box-shadow: 0 0 50px #FFD700;
}
.cloud {
position: absolute;
background: white;
border-radius: 50%;
opacity: 0.8;
animation: cloudMove linear infinite;
}
.title {
position: absolute;
top: 20px;
left: 0;
width: 100%;
text-align: center;
color: white;
font-size: 2.5em;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
z-index: 100;
}
.link {
position: absolute;
bottom: 20px;
left: 0;
width: 100%;
text-align: center;
z-index: 100;
}
.link a {
color: white;
background: rgba(255, 255, 255, 0.3);
padding: 10px 20px;
border-radius: 30px;
text-decoration: none;
font-weight: bold;
transition: all 0.3s;
}
.link a:hover {
background: rgba(255, 255, 255, 0.5);
}
@keyframes fly {
0% {
transform: translate(0, 0) rotate(0deg);
}
25% {
transform: translate(100px, 50px) rotate(10deg);
}
50% {
transform: translate(200px, 0) rotate(0deg);
}
75% {
transform: translate(100px, -50px) rotate(-10deg);
}
100% {
transform: translate(0, 0) rotate(0deg);
}
}
@keyframes flapLeft {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(60deg);
}
}
@keyframes flapRight {
0% {
transform: rotateY(0deg);
}
100% {
transform: rotateY(-60deg);
}
}
@keyframes cloudMove {
0% {
transform: translateX(-100px);
}
100% {
transform: translateX(calc(100vw + 100px));
}
}
</style>
</head>
<body>
<div class="forest-scene">
<h1 class="title">森林蝴蝶飞舞特效</h1>
<div class="sun"></div>
<!-- 云朵 -->
<div class="cloud" style="width: 100px; height: 60px; top: 80px; animation-duration: 60s;"></div>
<div class="cloud" style="width: 150px; height: 80px; top: 120px; animation-duration: 80s; animation-delay: -20s;"></div>
<div class="cloud" style="width: 80px; height: 50px; top: 150px; animation-duration: 50s; animation-delay: -30s;"></div>
<!-- 树木 -->
<div class="tree tree-1"></div>
<div class="tree tree-2"></div>
<div class="tree tree-3"></div>
<!-- 地面 -->
<div class="ground"></div>
<!-- 蝴蝶 -->
<div class="butterfly" style="top: 200px; left: 100px; animation-duration: 15s;">
<div class="left-wing"></div>
<div class="right-wing"></div>
<div class="body"></div>
</div>
<div class="butterfly" style="top: 300px; left: 300px; animation-duration: 20s; animation-delay: -5s;">
<div class="left-wing"></div>
<div class="right-wing"></div>
<div class="body"></div>
</div>
<div class="butterfly" style="top: 150px; left: 500px; animation-duration: 18s; animation-delay: -8s;">
<div class="left-wing"></div>
<div class="right-wing"></div>
<div class="body"></div>
</div>
<div class="butterfly" style="top: 250px; left: 700px; animation-duration: 25s; animation-delay: -12s;">
<div class="left-wing"></div>
<div class="right-wing"></div>
<div class="body"></div>
</div>
<div class="link">
</div>
</div>
<script>
// 动态创建更多蝴蝶
function createButterflies(count) {
const scene = document.querySelector('.forest-scene');
for (let i = 0; i < count; i++) {
const butterfly = document.createElement('div');
butterfly.className = 'butterfly';
// 随机位置
const left = Math.random() * window.innerWidth;
const top = Math.random() * (window.innerHeight - 200) + 50;
// 随机动画参数
const duration = 15 + Math.random() * 15;
const delay = -Math.random() * 15;
butterfly.style.left = `${left}px`;
butterfly.style.top = `${top}px`;
butterfly.style.animationDuration = `${duration}s`;
butterfly.style.animationDelay = `${delay}s`;
// 创建蝴蝶翅膀和身体
const leftWing = document.createElement('div');
leftWing.className = 'left-wing';
const rightWing = document.createElement('div');
rightWing.className = 'right-wing';
const body = document.createElement('div');
body.className = 'body';
butterfly.appendChild(leftWing);
butterfly.appendChild(rightWing);
butterfly.appendChild(body);
scene.appendChild(butterfly);
// 设置随机飞行路径
setRandomFlyAnimation(butterfly);
}
}
// 设置随机飞行路径
function setRandomFlyAnimation(butterfly) {
const keyframes = `
@keyframes fly-${Math.floor(Math.random() * 10000)} {
0% {
transform: translate(0, 0) rotate(0deg);
}
25% {
transform: translate(${Math.random() * 200 - 100}px, ${Math.random() * 100 - 50}px) rotate(${Math.random() * 30 - 15}deg);
}
50% {
transform: translate(${Math.random() * 200 - 100}px, ${Math.random() * 100 - 50}px) rotate(${Math.random() * 30 - 15}deg);
}
75% {
transform: translate(${Math.random() * 200 - 100}px, ${Math.random() * 100 - 50}px) rotate(${Math.random() * 30 - 15}deg);
}
100% {
transform: translate(0, 0) rotate(0deg);
}
}
`;
const style = document.createElement('style');
style.innerHTML = keyframes;
document.head.appendChild(style);
butterfly.style.animationName = `fly-${Math.floor(Math.random() * 10000)}`;
}
// 页面加载后创建蝴蝶
window.addEventListener('load', () => {
createButterflies(10); // 创建10只随机蝴蝶
});
</script>
</body>
</html>
1146

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



