-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (38 loc) · 1.23 KB
/
script.js
File metadata and controls
45 lines (38 loc) · 1.23 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
document.addEventListener("DOMContentLoaded", () => {
const navLinks = document.getElementById("nav-links");
const hamburger = document.getElementById("hamburger");
const carousel = document.querySelector(".carousel-track");
hamburger.addEventListener("click", () => {
navLinks.classList.toggle("active");
});
function showTab(tabId) {
document.querySelectorAll(".tab-content").forEach(tab => {
tab.classList.toggle("active", tab.id === tabId);
});
}
if (!location.hash) location.hash = "#tab-about";
showTab(location.hash.slice(1));
window.addEventListener("hashchange", () => {
showTab(location.hash.slice(1));
navLinks.classList.remove("active");
});
// Swipe for carousel
let startX = 0;
let isDown = false;
carousel.addEventListener("touchstart", e => {
isDown = true;
startX = e.touches[0].clientX;
carousel.style.animationPlayState = "paused";
});
carousel.addEventListener("touchmove", e => {
if (!isDown) return;
const x = e.touches[0].clientX;
const walk = (x - startX) * 0.5;
carousel.scrollLeft -= walk;
startX = x;
});
carousel.addEventListener("touchend", () => {
isDown = false;
carousel.style.animationPlayState = "running";
});
});