-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanimator.js
45 lines (38 loc) · 1.08 KB
/
animator.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
const textAnimator = function(){
let i = 0;
let progress = 0;
let textToWrite;
let container;
function decryptText(containerElement, textToAnimate){
textToWrite = textToAnimate;
container = containerElement;
animateText()
}
function animateText(){
setTimeout(function(){
i++;
let currentText = textToWrite.substr(0, i);
currentText += getRandomChars(textToWrite.length - i);
container.innerHTML = currentText;
progress = i/textToWrite.length;
if(progress < 1) {
animateText()
}
}, 100);
}
let codingChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
function getRandomChars(howMany) {
let result = '';
for(let i=0; i<howMany; i++) {
if(i % 5 == 0) {
result += ' '
} else {
result += codingChars.charAt(Math.floor(Math.random() * codingChars.length));
}
}
return result
}
return {
decryptText
}
}();