-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
188 lines (130 loc) · 4.42 KB
/
script.js
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Volunteer Swipper
const swiper = new Swiper('.swiper', {
// Optional parameters
direction: 'horizontal',
loop: true,
centeredSlides: true,
autoplay: {
delay: 3000,
disableOnInteraction: false,
},
resistance: false,
// Navigation arrows
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
// Breakpoints
slidesPerView: 1,
spaceBetween: 10,
breakpoints: {
// when window width is >= 320px
320: {
slidesPerView: 1,
spaceBetween: 20
},
// when window width is >= 480px
480: {
slidesPerView: 1,
spaceBetween: 10
},
// when window width is >= 640px
640: {
slidesPerView: 3,
spaceBetween: 10
},
// when window width is >= 800px
900: {
slidesPerView: 5,
spaceBetween: 10
},
// when window width is >= 120px
1200: {
slidesPerView: 7,
// spaceBetween: 10
}
},
});
const navigation = document.querySelector(".navbar");
const navbarNav = document.querySelector('#navbarNav');
const bodyWrapper = document.querySelector('.wrapper');
const navToggle = document.querySelector('.navbar-toggler');
// Resize event handler to display appropriate navbar type
window.addEventListener('resize', navDisplay)
function navDisplay() {
if (bodyWrapper.clientWidth >= '550') {
// Show nav items incase hidden from mobile
navbarNav.style.visibility = 'visible';
navbarNav.classList.remove('navbar-collapse');
navbarNav.classList.add('navbar-expand');
console.log('window resized');
} else {
navbarNav.classList.remove('navbar-expand');
navbarNav.classList.add('navbar-collapse');
}
}
navDisplay()
// Set Navbar height to --scroll-padding variable
const navigationHeight = navigation.offsetHeight;
document.documentElement.style.setProperty(
"--scroll-padding",
navigationHeight + "px"
);
// Mobile nav toggle button event handler
navToggle.addEventListener('click', () => {
//First Make nav elements visible to be clickable
navbarNav.style.visibility = 'visible';
if (navToggle.attributes.src.value == './images/menu-open.svg') {
navToggle.attributes.src.value = './images/menu-close.svg';
navbarNav.classList.replace('collapse', 'expand');
bodyWrapper.style.setProperty('filter', 'blur(5px)');
} else {
navToggle.attributes.src.value = "./images/menu-open.svg";
navbarNav.classList.replace('expand', 'collapse');
bodyWrapper.style.setProperty('filter', 'none');
}
})
// Hide navbar overlay when hidden on mobile
navbarNav.addEventListener('transitionend', (e) => {
if (e.propertyName === 'opacity') {
console.log(navbarNav.classList);
if (navbarNav.classList.contains('collapse') && bodyWrapper.clientWidth < 550) {
// To prevent users from clicking invisible nav elements overlay
navbarNav.style.visibility = 'hidden';
}
}
})
// change active nav element on click
navbarNav.addEventListener('click', (e) => {
if (!e.target.classList.contains('nav-link')) return;
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(el => {
if (el.classList.contains('active')) el.classList.remove('active');
})
e.target.classList.add('active');
});
// const toggleBtn = document.querySelector(".toggle-button");
// const sideBar = document.querySelector(".side-bar");
// const backdrop = document.querySelector(".backdrop");
// const closeMenuBtn = document.querySelector(".menu-close-btn");
// console.log(toggleBtn);
// console.log(sideBar);
// const openSideBar = (e) => {
// toggleBtn.style.display = "none";
// closeMenuBtn.style.display = "inline-block";
// sideBar.classList.remove("remove-side-bar");
// backdrop.classList.remove("remove-side-bar");
// sideBar.classList.add("open");
// backdrop.classList.add("open");
// };
// const closeSideBar = (e) => {
// toggleBtn.style.display = "block";
// closeMenuBtn.style.display = "none";
// sideBar.classList.add("remove-side-bar");
// backdrop.classList.add("remove-side-bar");
// sideBar.classList.remove("open");
// backdrop.classList.remove("open");
// };
// toggleBtn.addEventListener("click", openSideBar);
// backdrop.addEventListener("click", closeSideBar);
// closeMenuBtn.addEventListener("click", closeSideBar);