-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
86 lines (73 loc) · 2.27 KB
/
Copy pathmain.js
File metadata and controls
86 lines (73 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
(function initReveal() {
const reveals = document.querySelectorAll('.reveal');
if (!reveals.length) return;
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) entry.target.classList.add('visible');
});
},
{ threshold: 0.1 }
);
reveals.forEach((el) => observer.observe(el));
})();
(function initLightbox() {
const lb = document.getElementById('lightbox');
const lbi = document.getElementById('lightbox-img');
const closeBtn = lb?.querySelector('.lightbox__x');
if (!lb || !lbi) return;
function open(src, alt) {
lbi.src = src;
lbi.alt = alt || '';
lb.classList.add('open');
document.body.style.overflow = 'hidden';
}
function close() {
lb.classList.remove('open');
lbi.src = '';
document.body.style.overflow = '';
}
document.querySelectorAll('.gallery-card').forEach((card) => {
card.addEventListener('click', () => {
const img = card.querySelector('img');
open(card.dataset.src || img?.src || '', img?.alt || '');
});
});
lb.addEventListener('click', (e) => {
if (e.target === lb || e.target === closeBtn) close();
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && lb.classList.contains('open')) close();
});
})();
(function initVideoObserver() {
const videos = document.querySelectorAll('.hero-video, .feature-video');
if (!videos.length) return;
if (!('IntersectionObserver' in window)) {
videos.forEach((v) => v.play().catch(() => {}));
return;
}
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
const vid = entry.target;
if (entry.isIntersecting) vid.play().catch(() => {});
else vid.pause();
});
},
{ threshold: 0.15 }
);
videos.forEach((v) => observer.observe(v));
})();
(function initSmoothScroll() {
document.querySelectorAll('a[href^="#"]').forEach((link) => {
link.addEventListener('click', (e) => {
const id = link.getAttribute('href');
if (!id || id === '#') return;
const target = document.querySelector(id);
if (!target) return;
e.preventDefault();
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
});
});
})();