-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
56 lines (45 loc) · 1.29 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
// text to change
finaltext = "You might not see they but they see you";
const characters =
"!#$%&'()*+,-./:;<=>?@[]^_`{|}~ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
iterations = finaltext.length + 20;
function randomstr() {
n = Math.random();
n = n * characters.length;
n = Math.floor(n);
out = characters[n];
return out;
}
var text = [];
for (i = 0; i < finaltext.length; i++) {
t = [];
text.push(t);
}
for (i = 0; i < finaltext.length; i++) {
t = text[i];
for (j = 0; j < iterations - 20 * Math.random(); j++) {
t.push(randomstr());
}
t.push(finaltext[i]);
}
counter = 0;
const elemout = document.getElementById("animationoutput");
for (i = 0; i < finaltext.length; i++) {
const outputpart = document.createElement("div");
outputpart.classList.add("letters");
elemout.appendChild(outputpart);
outputlist = document.getElementsByClassName("letters");
}
function change() {
for (i = 0; i < finaltext.length; i++) {
ft = text[i];
if (counter < ft.length) {
outputlist[i].innerHTML = ft[counter];
} else {
outputlist[i].innerHTML = ft[ft.length - 1];
}
}
counter++;
}
const inst = setInterval(change, 150); //delay da animação
// this code is from https://codepen.io/beetran/pen/PomJdXO?editors=1000 - take a look there