-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample.js
More file actions
37 lines (32 loc) · 1.08 KB
/
sample.js
File metadata and controls
37 lines (32 loc) · 1.08 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
console.log("Portfolio site loaded successfully!");
// Highlight active nav link on scroll
window.addEventListener("scroll", () => {
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll("nav a");
let current = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop - 50;
if (pageYOffset >= sectionTop) {
current = section.getAttribute("id");
}
});
navLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href").includes(current)) {
link.classList.add("active");
}
});
});
// Smooth scroll behavior
const links = document.querySelectorAll("nav a");
links.forEach(link => {
link.addEventListener("click", function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute("href"));
target.scrollIntoView({ behavior: "smooth" });
});
});
// Dynamic year in footer
const footer = document.querySelector("footer p");
const year = new Date().getFullYear();
footer.innerHTML = `© ${year} My Portfolio. All rights reserved.`;