-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (51 loc) · 1.54 KB
/
script.js
File metadata and controls
60 lines (51 loc) · 1.54 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
54
55
56
57
58
59
60
// Scroll to Top Button
const scrollTopBtn = document.getElementById("scrollTopBtn");
window.onscroll = function () {
if (document.body.scrollTop > 300 || document.documentElement.scrollTop > 300) {
scrollTopBtn.style.display = "block";
} else {
scrollTopBtn.style.display = "none";
}
};
scrollTopBtn.addEventListener("click", () => {
window.scrollTo({ top: 0, behavior: "smooth" });
});
// Dark Mode Toggle
const toggleDarkMode = () => {
document.body.classList.toggle("dark-mode");
// Optional: store theme preference
if (document.body.classList.contains("dark-mode")) {
localStorage.setItem("theme", "dark");
} else {
localStorage.setItem("theme", "light");
}
};
// Load saved theme on page load
window.onload = () => {
const savedTheme = localStorage.getItem("theme");
if (savedTheme === "dark") {
document.body.classList.add("dark-mode");
}
};
// Typing Animation
const typingText = document.querySelector(".typing-text");
const textArray = ["Hi, I'm Anchal Bhandari", "Web Developer", "UI/UX Enthusiast"];
let index = 0;
let charIndex = 0;
let isDeleting = false;
function type() {
const currentText = textArray[index];
typingText.textContent = currentText.substring(0, charIndex);
if (!isDeleting && charIndex < currentText.length) {
charIndex++;
setTimeout(type, 100);
} else if (isDeleting && charIndex > 0) {
charIndex--;
setTimeout(type, 50);
} else {
isDeleting = !isDeleting;
if (!isDeleting) index = (index + 1) % textArray.length;
setTimeout(type, 1000);
}
}
type();