-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
66 lines (60 loc) · 1.93 KB
/
script.js
File metadata and controls
66 lines (60 loc) · 1.93 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
const poemLines = [
"(i thought the world would stop at 13 ",
"but hands spun; traveled. it was 16 instead.",
"beginnings sometimes look like ends",
"but i looked again, aged again)",
"",
"today i saw the shell of an egg on the sidewalk",
"baby blue and broken. dry.",
"the other day i saw a baby bird, eyes closed,",
"wings frozen, wet with morning dew—",
"it’d left the nest a little too soon. i wonder if",
"its mother knew that ",
"it would be too windy, too early",
"too late. the nights",
"these days are ",
"getting colder. i knelt down and ",
"cradled it close, closer: spread ",
"its wings before covering it with earth",
"the practiced motion of kneeling in",
"dirt and hiding and crying over",
"a tiny little dead thing",
"somehow giving me deja vu."
];
const replacementText = "beginnings sometimes look like ends";
const poemContainer = document.getElementById("poem");
function typeLine(line, index, callback) {
let span = document.createElement("span");
span.classList.add("line");
poemContainer.appendChild(span);
let charIndex = 0;
function typeCharacter() {
if (charIndex < line.length) {
span.textContent += line.charAt(charIndex);
charIndex++;
setTimeout(typeCharacter, 45);
} else {
span.style.opacity = 1;
if (callback) callback();
}
}
typeCharacter();
}
function typePoem(lines, index = 0) {
if (index < lines.length) {
typeLine(lines[index], index, () => {
poemContainer.appendChild(document.createElement("br"));
setTimeout(() => typePoem(lines, index + 1), 350);
});
} else {
setTimeout(() => replaceLines(), 1500);
}
}
function replaceLines(index = 0) {
const lines = document.querySelectorAll(".line");
if (index < lines.length) {
lines[index].textContent = replacementText;
setTimeout(() => replaceLines(index + 1), 500);
}
}
typePoem(poemLines);