-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
46 lines (40 loc) · 1.43 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
const burgerBtn = document.querySelector(".header__burger-btn");
const exitBtn = document.querySelector(".header__exit-btn");
const mobileMenu = document.querySelector(".header__mobile-menu");
function toggleMobileMenu(show) {
burgerBtn.style.display = show ? "none" : "block";
exitBtn.style.display = show ? "block" : "none";
mobileMenu.style.display = show ? "block" : "none";
}
function hideAll() {
burgerBtn.style.display = "none";
exitBtn.style.display = "none";
mobileMenu.style.display = "none";
}
function updateView() {
var windowWidth = window.innerWidth;
if (windowWidth > 768) {
hideAll();
returnImage();
} else {
toggleMobileMenu(mobileMenu.style.display === "block");
replaceImage();
}
}
function replaceImage() {
const familyPic = document.querySelector(".advantages__family-pic");
const header = document.querySelector("header");
const main = document.querySelector("main");
header.parentNode.insertBefore(familyPic, main);
}
function returnImage() {
const familyPic = document.querySelector(".advantages__family-pic");
const advantagesSection = document.querySelector(".advantages");
advantagesSection.prepend(familyPic);
}
document.addEventListener("DOMContentLoaded", function () {
burgerBtn.addEventListener("click", () => toggleMobileMenu(true));
exitBtn.addEventListener("click", () => toggleMobileMenu(false));
window.addEventListener("resize", updateView);
updateView();
});