forked from Sovietianqi/sovietianqi.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
30 lines (26 loc) · 852 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// 设置花瓣数量、速度和动画持续时间
const numPetals = 100;
const speed = 5;
const duration = 60;
// 初始化花瓣
const petals = [];
for (let i = 0; i < numPetals; i++) {
const petal = document.createElement('div');
petal.classList.add('petal');
document.getElementById('cherry-blossom').appendChild(petal);
petals.push(petal);
}
// 添加动画
for (let i = 0; i < petals.length; i++) {
const petal = petals[i];
const x = Math.random() * window.innerWidth;
const y = Math.random() * window.innerHeight;
const duration = Math.random() * 10 + 5;
const delay = Math.random() * 5 + 1;
petal.style.left = x + 'px';
*** = y + 'px';
petal.style.transition = `top ${duration}s linear ${delay}s, left ${duration}s linear ${delay}s`;
setTimeout(() => {
petal.remove();
}, duration * 1000 + delay * 1000);
}