-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
38 lines (33 loc) · 1.14 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
let words = document.querySelectorAll(".word")
words.forEach((word)=>{
let letters = word.textContent.split("");
word.textContent="";
letters.forEach((letter)=>{
let span = document.createElement("span");
span.textContent = letter;
span.className = "letter";
word.append(span);
});
});
let currentWordIndex = 0;
let maxWordIndex = words.length -1;
words[currentWordIndex].style.opacity="1";
let changeText = ()=>{
let cuurentWord =words[currentWordIndex];
let nextWord = currentWordIndex === maxWordIndex ? words[0]: words[currentWordIndex+1];
Array.from(cuurentWord.children).forEach((letter,i)=>{
setTimeout(()=>{
letter.className = "letter out";
},i* 80);
});
nextWord.style.opacity="1";
Array.from(nextWord.children).forEach((letter,i)=>{
letter.className = "letter behind";
setTimeout(()=>{
letter.className = "letter in";
} ,340 + i * 80);
});
currentWordIndex = currentWordIndex === maxWordIndex ? 0 : currentWordIndex + 1;
};
changeText();
setInterval(changeText,3000)