-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (32 loc) · 1005 Bytes
/
index.js
File metadata and controls
40 lines (32 loc) · 1005 Bytes
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
const toggleNav = () => {
document.body.dataset.nav =
document.body.dataset.nav === "true" ? "false" : "true";
};
let startY = 0;
let currentY = 0;
const navElement = document.querySelector("#nav");
navElement.addEventListener("touchstart", (e) => {
startY = e.touches[0].clientY;
});
navElement.addEventListener("touchmove", (e) => {
currentY = e.touches[0].clientY;
});
navElement.addEventListener("touchend", () => {
const diffY = currentY - startY;
const threshold = 50; // minimum swipe distance in pixels
if (Math.abs(diffY) > threshold) {
if (diffY > 0) {
// Swipe down
document.body.dataset.nav = "false";
} else {
// Swipe up
document.body.dataset.nav = "true";
}
}
});
let viewHeight = window.innerHeight * 0.01;
document.documentElement.style.setProperty("--vh", `${viewHeight}px`);
window.addEventListener("resize", () => {
let vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty("--vh", `${vh}px`);
});