-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
67 lines (57 loc) · 2.27 KB
/
Copy pathscripts.js
File metadata and controls
67 lines (57 loc) · 2.27 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
document.addEventListener("DOMContentLoaded", function() {
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll("nav ul li a");
const progressBar = document.querySelector("#progress-bar span");
const options = {
threshold: 0.5
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add("active");
navLinks.forEach(link => {
if (link.getAttribute('href').substring(1) === entry.target.id) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
} else {
entry.target.classList.remove("active");
}
});
}, options);
sections.forEach(section => {
observer.observe(section);
});
window.addEventListener("scroll", () => {
const scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
const scrollHeight = document.documentElement.scrollHeight - window.innerHeight;
const progressWidth = (scrollTop / scrollHeight) * 100;
progressBar.style.width = progressWidth + "%";
});
window.addEventListener("scroll", () => {
if (window.scrollY > 50) {
document.querySelector("header").classList.add("scrolled");
} else {
document.querySelector("header").classList.remove("scrolled");
}
});
document.querySelectorAll('.profile-pic, .hobbies-img, .about-overlay, .hobbies-overlay').forEach(element => {
element.addEventListener('click', function() {
const img = this.tagName === 'IMG' ? this : this.previousElementSibling;
openModal(img);
});
});
document.querySelector('.close').addEventListener('click', closeModal);
});
function openModal(img) {
const modal = document.getElementById("modal");
const modalImg = document.getElementById("modal-img");
modal.style.display = "block";
modalImg.src = img.src;
}
function closeModal() {
const modal = document.getElementById("modal");
modal.style.display = "none";
}