Repository navigation
Expand file tree
/
Copy pathscripts.js
More file actions
60 lines (52 loc) · 1.8 KB
/
Copy pathscripts.js
File metadata and controls
60 lines (52 loc) · 1.8 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
document.addEventListener('DOMContentLoaded', () => {
// --- Smooth Reveal On Scroll ---
function revealOnScroll() {
const reveals = document.querySelectorAll('.reveal');
reveals.forEach(el => {
const windowHeight = window.innerHeight;
const elementTop = el.getBoundingClientRect().top;
const elementVisible = 150; // Distance from the bottom of the screen to trigger the animation
if (elementTop < windowHeight - elementVisible) {
el.classList.add('visible');
} else {
el.classList.remove('visible');
}
});
}
window.addEventListener('scroll', revealOnScroll);
revealOnScroll(); // Trigger once on load
// --- Automatic Modal Wiring ---
const allModalTriggers = document.querySelectorAll('[data-modal-target]');
allModalTriggers.forEach(trigger => {
trigger.addEventListener('click', (e) => {
e.preventDefault();
const modalId = trigger.getAttribute('data-modal-target');
const modal = document.getElementById(modalId);
if (modal) {
modal.classList.add('show');
}
});
});
const allModals = document.querySelectorAll('.modal');
allModals.forEach(modal => {
// Close button inside the modal
const closeButton = modal.querySelector('.modal-close');
if (closeButton) {
closeButton.addEventListener('click', () => {
modal.classList.remove('show');
});
}
// Clicking on the dark background overlay to close
modal.addEventListener('click', (event) => {
if (event.target === modal) {
modal.classList.remove('show');
}
});
});
// Close any open modal with the 'Escape' key
window.addEventListener('keydown', (event) => {
if (event.key === 'Escape') {
document.querySelector('.modal.show')?.classList.remove('show');
}
});
});