forked from CodeYourFuture/HTML-CSS-Coursework-Week3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
53 lines (44 loc) · 1.01 KB
/
main.js
File metadata and controls
53 lines (44 loc) · 1.01 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
const random_char = () => {
const possible =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz";
return possible.charAt(Math.floor(Math.random() * possible.length));
};
const mask = (chars, progress) => {
const masked = [];
for (let i = 0; i < chars.length; i++) {
const position = (i + 1) / chars.length;
if (position > progress) {
masked.push(random_char());
} else {
masked.push(chars[i]);
}
}
return masked.join('');
};
const shuffle = el => {
const chars = el.textContent.split('');
const params = {
progress: 0
};
const a = anime({
targets: params,
progress: 1,
delay: 1000,
duration: 1000,
easing: 'easeInQuad',
update: () => {
el.textContent = mask(chars, params.progress);
},
complete: () => {
el.classList.add('completed');
}
});
el.onclick = () => {
el.classList.remove('completed');
a.restart();
};
};
for (const el of document.querySelectorAll('.nav-b')) {
shuffle(el);
}