- 新增triumph.mp3作为胜利音效 - 优化guess.css中的动画效果和布局 - 调整guess.js中的音频播放逻辑和状态管理 - 更新guess.html页面结构和样式 - 修改song-request-station.js中的音频源路径
96 lines
4.1 KiB
HTML
96 lines
4.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Item Appear Animation</title>
|
|
<link rel="stylesheet" href="styles.css" />
|
|
<style>
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="box" id="animationContainer">
|
|
<div class="wave-bg"></div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const container = document.getElementById('animationContainer');
|
|
let containerWidth = container.offsetWidth;
|
|
let containerHeight = container.offsetHeight;
|
|
|
|
// 颜色数组
|
|
const colors = [
|
|
'#FF6B6B', '#4ECDC4', '#45B7D1', '#FFA5A5', '#845EC2',
|
|
'#D65DB1', '#FF6F91', '#FF9671', '#FFC75F', '#F9F871',
|
|
'#00B894', '#0984E3', '#6C5CE7', '#A29BFE', '#FD79A8'
|
|
];
|
|
|
|
// 创建指定数量的动画元素
|
|
const createAnimatedItems = (count) => {
|
|
for (let i = 0; i < count; i++) {
|
|
setTimeout(() => {
|
|
createSingleItem();
|
|
}, i * 100); // 每个元素间隔100ms创建
|
|
}
|
|
};
|
|
|
|
// 创建单个动画元素
|
|
const createSingleItem = () => {
|
|
const item = document.createElement('div');
|
|
item.classList.add('animated-item');
|
|
|
|
// 随机大小
|
|
const size = Math.random() * 60 + 20; // 20-80px
|
|
item.style.width = `${size}px`;
|
|
item.style.height = `${size}px`;
|
|
|
|
// 随机颜色
|
|
const color = colors[Math.floor(Math.random() * colors.length)];
|
|
item.style.backgroundColor = color;
|
|
|
|
// 随机位置,确保在容器内
|
|
const left = Math.random() * (containerWidth - size);
|
|
const top = Math.random() * (containerHeight - size - 100) + 50; // 避开底部波浪
|
|
item.style.left = `${left}px`;
|
|
item.style.top = `${top}px`;
|
|
|
|
// 设置入场动画
|
|
const appearDuration = Math.random() * 0.5 + 0.5; // 0.5-1s
|
|
item.style.animation = `appear ${appearDuration}s forwards`;
|
|
|
|
container.appendChild(item);
|
|
|
|
// 入场动画完成后添加移动动画
|
|
setTimeout(() => {
|
|
const moveDuration = Math.random() * 2 + 3; // 3-5s
|
|
item.style.animation = `appear ${appearDuration}s forwards, move ${moveDuration}s ease-in-out infinite`;
|
|
}, appearDuration * 1000);
|
|
|
|
// 随机时间后移除元素并创建新元素
|
|
const lifeTime = Math.random() * 5 + 8; // 8-13s
|
|
setTimeout(() => {
|
|
// 退场动画
|
|
item.style.animation = `appear ${appearDuration}s reverse forwards`;
|
|
setTimeout(() => {
|
|
container.removeChild(item);
|
|
// 创建新元素替代
|
|
createSingleItem();
|
|
}, appearDuration * 1000);
|
|
}, lifeTime * 1000);
|
|
};
|
|
|
|
// 初始创建20个元素
|
|
createAnimatedItems(20);
|
|
|
|
// 窗口大小改变时重新计算容器尺寸
|
|
window.addEventListener('resize', () => {
|
|
containerWidth = container.offsetWidth;
|
|
containerHeight = container.offsetHeight;
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|