-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (38 loc) · 1.36 KB
/
Copy pathindex.js
File metadata and controls
47 lines (38 loc) · 1.36 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
document.addEventListener('DOMContentLoaded', function() {
const sidebar = document.getElementById('sidebar');
const hamburgerMenu = document.getElementById('hamburger-menu');
let isMobile = window.matchMedia("(max-width: 480px)").matches;
let isNavigating = false;
hamburgerMenu.addEventListener('click', function() {
sidebar.classList.toggle('active');
});
function hideSidebar() {
if (isMobile && sidebar.classList.contains('active')) {
sidebar.classList.remove('active');
}
}
document.addEventListener('click', function(event) {
if (isMobile && !sidebar.contains(event.target) && !hamburgerMenu.contains(event.target)) {
hideSidebar();
}
});
sidebar.addEventListener('click', function(event) {
if (event.target.tagName === 'A') {
isNavigating = true;
}
});
sidebar.addEventListener('transitionend', function() {
setTimeout(() => isNavigating = false, 500);
});
document.addEventListener('scroll', function(event) {
if (isMobile && !isNavigating && !sidebar.contains(event.target)) {
hideSidebar();
}
}, true);
window.addEventListener('resize', function() {
isMobile = window.matchMedia("(max-width: 480px)").matches;
});
AOS.init({
duration: 1200,
});
});