-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
72 lines (61 loc) · 2.28 KB
/
main.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
document.addEventListener('DOMContentLoaded', function() {
const taglines = [
"Full-stack Web Developer",
"Mobile App Creator",
"Discord Bot Engineer",
"Web App Innovator"
];
const htmlEl = document.querySelector("html");
const darkModeButton = document.getElementById("sunMoonIcon");
const typingText = document.getElementById('tagline-text');
const hamburger = document.getElementById("hamburger");
const navbar = document.getElementById("navbar");
const navLinks = document.querySelectorAll("#navbar a:not(#hamburger) a:not(#sunMoonIcon)");
let activeLink = null;
let taglineIndex = 0;
const currentTheme = () => localStorage.getItem("theme") || (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light");
function typeTagline() {
let currentTagline = taglines[taglineIndex];
let charIndex = 0;
function type() {
if (charIndex < currentTagline.length) {
typingText.textContent += currentTagline.charAt(charIndex);
charIndex++;
setTimeout(type, 100);
} else {
setTimeout(erase, 1500); // Delay before erasing
}
}
function erase() {
if (charIndex > 0) {
typingText.textContent = currentTagline.substring(0, charIndex - 1);
charIndex--;
setTimeout(erase, 50);
} else {
taglineIndex = (taglineIndex + 1) % taglines.length;
currentTagline = taglines[taglineIndex];
setTimeout(type, 500);
}
}
type(); // Start typing
}
typeTagline(); // initiate the typing
hamburger.addEventListener("click", () => navbar.classList.toggle("responsive"));
navLinks.forEach(link => {
link.addEventListener("click", () => {
if (activeLink) activeLink.classList.remove("active");
link.classList.add("active");
activeLink = link;
navbar.classList.remove("responsive");
});
});
const theme = currentTheme();
htmlEl.dataset.theme = theme;
darkModeButton.textContent = (theme === "light") ? "☀︎" : "🌜";
darkModeButton.addEventListener("click", () => {
const newTheme = (currentTheme() === "dark") ? "light" : "dark";
htmlEl.dataset.theme = newTheme;
localStorage.setItem("theme", newTheme);
darkModeButton.textContent = (newTheme === "light") ? "☀︎" : "🌜";
});
});