You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
867 B
JavaScript
36 lines
867 B
JavaScript
let background = document.getElementById("background");
|
|
let stanze = document.getElementsByClassName("stanza");
|
|
let reset = document.getElementById("reset");
|
|
|
|
reset.addEventListener("click", (e) => {
|
|
quotes = getQuotes();
|
|
lifeboat = lifeboats();
|
|
offset = Math.floor((Math.random() * background.innerHTML.length) / 2);
|
|
});
|
|
|
|
let sea = background.innerHTML;
|
|
let quotes = getQuotes();
|
|
let lifeboat = lifeboats();
|
|
let offset = 0;
|
|
|
|
setInterval(() => moveText(), 100);
|
|
|
|
function getQuotes() {
|
|
let stanza = stanze[Math.floor(Math.random() * stanze.length)];
|
|
return stanza.getElementsByClassName("quote");
|
|
}
|
|
|
|
function lifeboats() {
|
|
let boats = "";
|
|
Array.from(quotes).forEach((quote) => {
|
|
boats += quote.outerHTML;
|
|
});
|
|
return boats;
|
|
}
|
|
|
|
function moveText() {
|
|
let text = sea.slice(0, offset) + lifeboat + sea.slice(offset);
|
|
background.innerHTML = text;
|
|
offset++;
|
|
}
|