-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
53 lines (43 loc) · 1.13 KB
/
main.js
File metadata and controls
53 lines (43 loc) · 1.13 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
// TYPEWRITER
const text = [
"Code · Train · Secure",
"Web & App Development",
"Cyber Security Training",
"Startup from Bangladesh"
];
let index = 0;
let charIndex = 0;
function type() {
const el = document.getElementById("typing");
if (!el) return;
let currentText = text[index];
el.innerHTML = currentText.substring(0, charIndex);
charIndex++;
if (charIndex > currentText.length) {
setTimeout(erase, 1500);
} else {
setTimeout(type, 90);
}
}
function erase() {
const el = document.getElementById("typing");
let currentText = text[index];
el.innerHTML = currentText.substring(0, charIndex);
charIndex--;
if (charIndex < 0) {
index = (index + 1) % text.length;
setTimeout(type, 200);
} else {
setTimeout(erase, 40);
}
}
// INIT
document.addEventListener("DOMContentLoaded", () => {
type();
// NAV SCROLL
window.addEventListener("scroll", () => {
const nav = document.querySelector("nav");
if (window.scrollY > 50) nav.classList.add("shrink");
else nav.classList.remove("shrink");
});
});