-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
90 lines (74 loc) · 1.89 KB
/
scripts.js
File metadata and controls
90 lines (74 loc) · 1.89 KB
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
class Chapter17 {
constructor(text1, text2, id) {
this.text1 = text1;
this.speed = 200;
this.text2 = text2;
this.time = [500, 50, 20, 10, 40, 100];
this.id = id;
this.k = 0;
this.iteration = 0;
this.showing = this.text1;
this.interval = null;
this.type();
}
type() {
if (this.k < this.text1.length) {
document.getElementById("text").innerHTML += this.text1.charAt(this.k);
this.k++;
setTimeout(this.type.bind(this), this.speed);
}
}
decreaseOpacity(i) {
if (i >= 0) {
this.getH2().style.opacity = `${i}`
i -= 0.01;
setTimeout(this.decreaseOpacity.bind(this), 65, i)
}
}
shuffleString(string) {
let array = string.split("");
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array.join("");
}
setH2(showing) {
this.getH2().innerHTML = showing;
}
getH2() {
return document.querySelector(`${this.id}`);
}
main() {
let target = this.getH2();
let iteration = this.iteration;
clearInterval(this.interval);
let onsec = () => {
if (target.innerText.length - 1 < iteration) {
this.showing = this.text2;
this.setH2(this.showing);
clearInterval(this.interval);
this.decreaseOpacity(1);
return;
}
this.setH2(this.shuffleString(this.text1));
if (iteration >= this.text1.length) {
clearInterval(this.interval);
}
iteration += 1 / 3;
};
this.interval = setInterval(onsec, 30);
}
}
const revelation = new Chapter17(
"TOM MARVOLO RIDDLE",
"I AM LORD VOLDEMORT",
"h2"
);
let handler = (event) => {
revelation.main();
event.target.removeEventListener("mouseover", handler);
};
document
.querySelector(`${revelation.id}`)
.addEventListener("mouseover", handler);