-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
59 lines (51 loc) · 2.04 KB
/
scripts.js
File metadata and controls
59 lines (51 loc) · 2.04 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
// Signal that JS is available (enables fade-in CSS)
document.documentElement.classList.add('js');
// ===== Active nav link =====
(function () {
const path = window.location.pathname;
document.querySelectorAll('.nav-link').forEach(function (link) {
const href = link.getAttribute('href');
const matchesPath = path === '/' + href;
const isHomeDefault = href === 'index.html' && path === '/';
if (matchesPath || isHomeDefault) {
link.classList.add('active');
}
});
})();
// ===== Fade-in on scroll =====
(function () {
const observer = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.fade-in').forEach(function (el) {
observer.observe(el);
});
})();
// ===== Project filter =====
(function () {
const pills = document.querySelectorAll('.filter-pill');
if (!pills.length) return;
pills.forEach(function (pill) {
pill.addEventListener('click', function () {
pills.forEach(function (p) { p.classList.remove('active'); });
pill.classList.add('active');
const tag = pill.dataset.filter;
document.querySelectorAll('.card[data-tags]').forEach(function (card) {
const tags = card.dataset.tags.split(' ');
const show = tag === 'all' || tags.includes(tag);
card.style.display = show ? '' : 'none';
if (show) card.classList.add('visible');
});
document.querySelectorAll('.section-group').forEach(function (group) {
const hasVisible = Array.from(group.querySelectorAll('.card[data-tags]'))
.some(function (c) { return c.style.display !== 'none'; });
group.style.display = hasVisible ? '' : 'none';
});
});
});
})();