-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
33 lines (29 loc) · 1006 Bytes
/
Copy pathscript.js
File metadata and controls
33 lines (29 loc) · 1006 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
const menuItems = document.querySelectorAll('.image_menu');
//The image of a menu defines the size of its container.
menuItems.forEach(item => {
const img = item.querySelector('.menu_image');
const text = item.querySelector('.text');
if(img){
if (img.complete) {
setWidth();
} else {
img.onload = setWidth;
}
function setWidth() {
const imgWidth = img.offsetWidth;
item.style.width = imgWidth + 'px';
text.style.width = imgWidth + 'px';
}
} else{
item.style.width = '';
text.style.width = '';
}
});
document.addEventListener("DOMContentLoaded", () => {
const toggle = document.querySelector(".nav-toggle");
const links = document.querySelector(".nav-links");
toggle.addEventListener("click", () => {
const isOpen = links.classList.toggle("active");
toggle.setAttribute("aria-expanded", isOpen);
});
});