-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
122 lines (111 loc) · 3.87 KB
/
script.js
File metadata and controls
122 lines (111 loc) · 3.87 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const navbarMenu = document.getElementById("menu");
const burgerMenu = document.getElementById("burger");
const headerMenu = document.getElementById("header");
// Open Close Navbar Menu on Click Burger
if (burgerMenu && navbarMenu) {
burgerMenu.addEventListener("click", () => {
burgerMenu.classList.toggle("is-active");
navbarMenu.classList.toggle("is-active");
});
}
// Close Navbar Menu on Click Menu Links
document.querySelectorAll(".menu-link").forEach((link) => {
link.addEventListener("click", () => {
burgerMenu.classList.remove("is-active");
navbarMenu.classList.remove("is-active");
});
});
// Change Header Background on Scrolling
window.addEventListener("scroll", () => {
if (this.scrollY >= 85) {
headerMenu.classList.add("on-scroll");
} else {
headerMenu.classList.remove("on-scroll");
}
});
// Fixed Navbar Menu on Window Resize
window.addEventListener("resize", () => {
if (window.innerWidth > 768) {
if (navbarMenu.classList.contains("is-active")) {
navbarMenu.classList.remove("is-active");
}
}
});
document.addEventListener("DOMContentLoaded", function (event) {
// Hide all sections except the home section initially
const sections = document.querySelectorAll('.section');
sections.forEach(section => {
if (section.id !== 'home') {
section.style.display = 'none';
}
});
brand.onclick = function () {
document.querySelectorAll('.menu-link').forEach(link => {
console.log(link.innerText)
if (link.innerText != 'Home') {
link.classList.remove('active');
} else {
link.classList.add('active');
}
});
sections.forEach(section => {
if (section.id != 'home') {
section.style.display = 'none';
} else {
section.style.display = 'block';
}
});
}
explore_btn.onclick = function () {
sections.forEach(section => {
if (section.id != 'explore') {
section.style.display = 'none';
} else {
section.style.display = 'block';
}
});
document.querySelectorAll('.menu-link').forEach(link => link.classList.remove('active'));
window.history.replaceState(null, null, "#explore");
}
if(window.location.hash) {
const frag = ['events', 'home', 'about', 'tools', 'explore'];
const _h = window.location.hash.substring(1);
if (frag.includes(_h)) {
sections.forEach(section => {
if (section.id != _h) {
section.style.display = 'none';
} else {
section.style.display = 'block';
}
});
document.querySelectorAll('.menu-link').forEach(link => {
if (link.innerText.toLowerCase() != _h) {
link.classList.remove('active');
} else {
link.classList.add('active');
}
});
}
}
// Add click event listeners to navbar links
const navLinks = document.querySelectorAll('.menu-link');
navLinks.forEach(link => {
link.addEventListener('click', function (event) {
event.preventDefault();
const targetId = this.getAttribute('href').substring(1);
// Hide all sections
sections.forEach(section => {
section.style.display = 'none';
});
// Show the target section
document.getElementById(targetId).style.display = 'block';
// Remove active class from all links
navLinks.forEach(link => {
link.classList.remove('active');
});
// Add active class to the clicked link
this.classList.add('active');
window.history.replaceState(null, null, "#" + targetId);
});
});
});