-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
168 lines (144 loc) · 3.38 KB
/
script.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// the fromTo() method
var tween = KUTE.fromTo(
"#snow1",
{ path: "#snow1" },
{ path: "#snow2" },
{
// options
delay: 2000,
easing: "easingCubicInOut",
yoyo: true,
repeat: 0,
duration: 50000,
}
).start();
//Set initial barrage of snow here
for (let i = 0; i < 100; i++) {
let flake = document.createElement("img");
flake.setAttribute("src", "flake.svg");
flake.setAttribute("class", "flake");
flake.style.position = "absolute";
let randPos = Math.random() * 101;
flake.style.left = randPos + "%";
let randSize = Math.random() * 0.5;
flake.setAttribute("width", randSize + "%");
document.body.appendChild(flake);
drift(flake, 9000, 900);
}
//make the snow continue to fall here
let snowFall = setInterval(function () {
let flake = document.createElement("img");
flake.setAttribute("src", "flake.svg");
flake.setAttribute("class", "flake");
flake.style.position = "absolute";
let randPos = Math.random() * 101;
flake.style.left = randPos + "%";
flake.style.top = "-2%";
let randSize = Math.random() * 0.3;
flake.setAttribute("width", randSize + "%");
document.body.appendChild(flake);
drift(flake, 2000, 200);
}, 35); //Set how fast new snowflakes should spawn
function drift(element, speedX, speedY) {
//variables
let randomRotation = Math.floor(Math.random() * 150);
let endRotation = Math.floor(Math.random() * 100);
let endPositionX = Math.floor(Math.random() * speedX + 500);
let endPositionY = Math.floor(Math.random() * speedY + 100);
let keyframes = [
{
transform:
"rotate(" + randomRotation + "deg) translateX(0%) translateY(0%)",
},
{
transform:
"rotate(" +
endRotation +
"deg) translateX(" +
endPositionX +
"%) translateY(" +
endPositionY +
"%)",
},
];
let options = {
duration: 3000,
iterations: 1,
fill: "forwards",
easing: "ease",
};
element.animate(keyframes, options);
let elementeRef = element;
slowDescent(element);
}
function slowDescent(element) {
let keyframes = [
{
transform:
"rotate(0deg) translateX(" +
element.style.translateY +
") translateY(" +
element.style.translateY +
")",
},
{
transform: "rotate(100deg) translateX(15000%) translateY(15000%)",
},
];
let options = {
duration: 9000,
delay: 1000,
iterations: 1,
fill: "forwards",
easing: "ease",
};
element.animate(keyframes, options);
landingAnimation(element);
fadeOut(element);
}
function landingAnimation(element) {
let keyframes = [
{
transform:
"rotate(0deg) translateX(" +
element.style.translateY +
") translateY(" +
element.style.translateY +
")",
opacity: 1,
},
{
transform: "rotate(100deg) translateX(150000%) translateY(150000%)",
opacity: 0,
},
];
let options = {
duration: 70000,
delay: 4000,
iterations: 1,
fill: "forwards",
easing: "ease",
};
element.animate(keyframes, options);
}
function fadeOut(element) {
let keyframes = [
{
opacity: 1,
},
{
opacity: 0,
},
];
let options = {
duration: 5000,
delay: 6000,
iterations: 1,
fill: "forwards",
easing: "ease",
};
element.animate(keyframes, options);
setTimeout(function () {
element.remove();
}, 13000);
}