-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
81 lines (69 loc) · 2.69 KB
/
Copy pathscript.js
File metadata and controls
81 lines (69 loc) · 2.69 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
const revealItems = document.querySelectorAll('.reveal');
if ('IntersectionObserver' in window) {
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
},
{ threshold: 0.12 }
);
revealItems.forEach((item, index) => {
item.style.transitionDelay = `${Math.min(index % 4, 3) * 70}ms`;
observer.observe(item);
});
} else {
revealItems.forEach((item) => item.classList.add('visible'));
}
document.querySelectorAll('[data-copy]').forEach((button) => {
button.addEventListener('click', async () => {
const label = button.querySelector('span');
try {
await navigator.clipboard.writeText(button.dataset.copy);
label.textContent = 'Copied';
} catch {
label.textContent = 'Select';
}
window.setTimeout(() => {
label.textContent = 'Copy';
}, 1600);
});
});
document.querySelectorAll('[data-carousel]').forEach((carousel) => {
const track = carousel.querySelector('[data-carousel-track]');
const slides = Array.from(carousel.querySelectorAll('[data-carousel-slide]'));
const previousButton = carousel.querySelector('[data-carousel-prev]');
const nextButton = carousel.querySelector('[data-carousel-next]');
const currentLabel = carousel.querySelector('[data-carousel-current]');
let currentIndex = 0;
let touchStartX = 0;
const showSlide = (nextIndex) => {
currentIndex = (nextIndex + slides.length) % slides.length;
track.style.transform = `translateX(-${currentIndex * 100}%)`;
currentLabel.textContent = String(currentIndex + 1).padStart(2, '0');
slides.forEach((slide, index) => {
const active = index === currentIndex;
slide.setAttribute('aria-hidden', String(!active));
if ('inert' in slide) slide.inert = !active;
});
};
previousButton.addEventListener('click', () => showSlide(currentIndex - 1));
nextButton.addEventListener('click', () => showSlide(currentIndex + 1));
carousel.addEventListener('keydown', (event) => {
if (event.key === 'ArrowLeft') showSlide(currentIndex - 1);
if (event.key === 'ArrowRight') showSlide(currentIndex + 1);
});
carousel.addEventListener('touchstart', (event) => {
touchStartX = event.changedTouches[0].clientX;
}, { passive: true });
carousel.addEventListener('touchend', (event) => {
const distance = event.changedTouches[0].clientX - touchStartX;
if (Math.abs(distance) < 45) return;
showSlide(currentIndex + (distance < 0 ? 1 : -1));
}, { passive: true });
showSlide(0);
});
document.querySelector('#year').textContent = new Date().getFullYear();