-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
56 lines (50 loc) · 1.77 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
var anchors = document.getElementsByTagName("div");
var length = anchors.length;
var el;
var color = ["#009900", "#0066ff", "#ff9900", "#ff0000", "#ffff66"];
var message = document.getElementById("message");
while (length--) {
el = anchors[length];
el.innerHTML = el.innerHTML
.replace(/</g, '<span class="leave"><</span>')
.replace(/>/g, '<span class="leave">></span>')
.replace(/o/g, '<span class="ornament1 ornament">o</span>')
.replace(/O/g, '<span class="ornament0 ornament">O</span>')
.replace(/@/g, '<span class="ornament2 ornament">@</span>')
.replace(/\*/g, '<span class="ornament3 ornament">*</span>');
}
function change() {
message.innerHTML = "Merry Christmas"
.split("")
.map((e) => {
i = Math.floor(Math.random() * 5);
return '<span class="ornament' + i + '-up">' + e + "</span>";
})
.join("");
}
window.setInterval(change, 500);
change();
var id, id2;
leaves = document.getElementsByClassName("leave");
leavenb = 0;
function lightleave() {
leaves[leaves.length - leavenb - 1].classList.add("leave-up");
leavenb++;
if (leavenb === leaves.length) {
window.clearInterval(id);
id2 = window.setInterval(lightornament, 5);
}
}
id = window.setInterval(lightleave, 5);
ornaments = [].slice.call(document.getElementsByClassName("ornament"));
function lightornament() {
i = Math.floor(Math.random() * ornaments.length)
ornament = ornaments[i];
cl = ornament.className;
if(cl.includes("0")) ornament.classList.add("ornament0-up")
else if(cl.includes("1")) ornament.classList.add("ornament1-up")
else if(cl.includes("2")) ornament.classList.add("ornament2-up")
else if(cl.includes("3")) ornament.classList.add("ornament3-up")
ornaments.splice(i, 1)
if (ornaments.length == 0) window.clearInterval(id2);
}