forked from shabro4549/topia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
138 lines (110 loc) · 4.08 KB
/
index.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
const elts = {
text1: document.getElementById("text1"),
text2: document.getElementById("text2"),
};
const texts = [
"",
"Deep in the jungle",
"where the creatures play",
"You are invited",
"to dance the night away",
];
const morphTime = 1.5;
const cooldownTime = 1;
let textIndex = -1;
let time = new Date();
let morph = 0;
let cooldown = cooldownTime;
elts.text1.textContent = texts[textIndex % texts.length];
elts.text2.textContent = texts[(textIndex + 1) % texts.length];
function doMorph() {
morph -= cooldown;
cooldown = 0;
let fraction = morph / morphTime;
if (fraction > 1) {
cooldown = cooldownTime;
fraction = 1;
}
setMorph(fraction);
}
function setMorph(fraction) {
elts.text2.style.filter = `blur(${Math.min(8 / fraction - 8, 100)}px)`;
elts.text2.style.opacity = `${Math.pow(fraction, 0.4) * 100}%`;
fraction = 1 - fraction;
elts.text1.style.filter = `blur(${Math.min(8 / fraction - 8, 100)}px)`;
elts.text1.style.opacity = `${Math.pow(fraction, 0.4) * 100}%`;
elts.text1.textContent = texts[textIndex % texts.length];
elts.text2.textContent = texts[(textIndex + 1) % texts.length];
}
function doCooldown() {
morph = 0;
elts.text2.style.filter = "";
elts.text2.style.opacity = "100%";
elts.text1.style.filter = "";
elts.text1.style.opacity = "0%";
}
function animate() {
if (textIndex < texts.length - 1) {
requestAnimationFrame(animate);
let newTime = new Date();
let shouldIncrementIndex = cooldown > 0;
let dt = (newTime - time) / 1000;
time = newTime;
cooldown -= dt;
if (cooldown <= 0) {
if (shouldIncrementIndex) {
textIndex++;
}
doMorph();
} else {
doCooldown();
}
} else {
if (abort) {
return;
} else {
console.log("done");
document.getElementById("but").style.visibility = "visible";
document.getElementById("but").addEventListener("click", animateTopia);
}
}
}
function animateTopia() {
console.log("Ready");
setTimeout(() => {
document.getElementById(
"description-black-background-wrapper"
).style.visibility = "visible";
document.getElementById("leaf-bottom").style.display = "none";
}, 9000);
document.getElementById("but").style.visibility = "hidden";
document.getElementById("text1").style.visibility = "hidden";
document.getElementById("text2").style.visibility = "hidden";
document.getElementById("skip").style.visibility = "hidden";
document.getElementById("overlay").style.visibility = "visible";
document.getElementById("leaf-top").classList.add("fade-leaves");
document.getElementById("leaf-top").style.visibility = "visible";
document.getElementById("leaf-bottom").classList.add("fade-leaves");
document.getElementById("leaf-bottom").style.visibility = "visible";
document.getElementById("jpg").classList.add("fade-logo");
document.getElementById("presents").classList.add("fade-presents");
document.getElementById("presents").style.visibility = "visible";
document.getElementById("presents").style.opacity = "0";
document.getElementById("topia-leaves").classList.add("fade-topia");
document.getElementById("topia-leaves").style.opacity = "0";
document.getElementById("topia-leaves").style.visibility = "visible";
document.getElementById("host").style.display = "block";
document.getElementById("host").classList.add("fade-collections");
document.getElementById("need-a-code").classList.add("fade-collections");
// document.getElementById("need-a-code").style.visibility = "visible";
document.getElementById("description").classList.add("fade-description");
document.getElementById("description").style.visibility = "visible";
document.getElementById("description").style.opacity = "0";
document.getElementById("details").classList.add("fade-details");
document.getElementById("details").style.visibility = "visible";
document.getElementById("details").style.opacity = "0";
document.getElementById("input").classList.add("fade-input");
document.getElementById("input").style.visibility = "visible";
document.getElementById("input").style.opacity = "0";
}
// animate();