-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
113 lines (89 loc) · 3.12 KB
/
Copy pathscript.js
File metadata and controls
113 lines (89 loc) · 3.12 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
document.documentElement.classList.add("js");
const sections = document.querySelectorAll("main section");
const navLinks = document.querySelectorAll("nav a");
const cursorGlow = document.querySelector(".cursor-glow");
const themeToggle = document.querySelector(".theme-toggle");
const themeIcon = document.querySelector("#themeIcon");
const revealItems = document.querySelectorAll(".reveal");
const heroBadges = document.querySelectorAll(".hero-badges span");
function setActiveLink() {
let currentSection = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop;
if (window.scrollY >= sectionTop - 180) {
currentSection = section.getAttribute("id");
}
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - 5) {
currentSection = sections[sections.length - 1].getAttribute("id");
}
});
navLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${currentSection}`) {
link.classList.add("active");
}
});
}
function setTheme(theme) {
document.documentElement.setAttribute("data-theme", theme);
localStorage.setItem("theme", theme);
if (themeIcon) {
themeIcon.textContent = theme === "dark" ? "🔆" : "🌙";
}
}
const savedTheme = localStorage.getItem("theme") || "dark";
setTheme(savedTheme);
if (themeToggle) {
themeToggle.addEventListener("click", () => {
const currentTheme = document.documentElement.getAttribute("data-theme");
const newTheme = currentTheme === "dark" ? "light" : "dark";
setTheme(newTheme);
});
}
window.addEventListener("scroll", setActiveLink);
window.addEventListener("load", setActiveLink);
window.addEventListener("mousemove", (event) => {
if (cursorGlow) {
cursorGlow.style.left = `${event.clientX}px`;
cursorGlow.style.top = `${event.clientY}px`;
}
heroBadges.forEach((badge, index) => {
const speed = (index + 1) * 0.008;
const x = (window.innerWidth / 2 - event.clientX) * speed;
const y = (window.innerHeight / 2 - event.clientY) * speed;
badge.style.transform = `translate(${x}px, ${y}px)`;
});
});
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add("visible");
}
});
},
{
threshold: 0.12,
}
);
revealItems.forEach((item) => observer.observe(item));
function initializeTabs() {
const tabGroups = document.querySelectorAll(".tab-group");
tabGroups.forEach((group) => {
const buttons = group.querySelectorAll(".tab-button");
const contents = group.querySelectorAll(".tab-content");
buttons.forEach((button) => {
button.addEventListener("click", () => {
const targetId = button.getAttribute("data-tab");
buttons.forEach((btn) => btn.classList.remove("active"));
contents.forEach((content) => content.classList.remove("active"));
button.classList.add("active");
const targetContent = group.querySelector(`#${targetId}`);
if (targetContent) {
targetContent.classList.add("active");
}
});
});
});
}
initializeTabs();