Skip to content

Commit

Permalink
fix close burger menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Metaldetect committed Jun 27, 2023
1 parent c35080a commit ec3cc4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
36 changes: 14 additions & 22 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
// Get the modal
var modal = document.getElementById("myModal");
// const modal = document.getElementById("myModal");
// const btn = document.getElementById("myBtn");
// const span = document.getElementsByClassName("close")[0];

// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// btn.onclick = function () {
// modal.style.display = "block";
// };

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// span.onclick = function () {
// modal.style.display = "none";
// };

// When the user clicks the button, open the modal
btn.onclick = function () {
modal.style.display = "block";
};

// When the user clicks on <span> (x), close the modal
span.onclick = function () {
modal.style.display = "none";
};

// When the user clicks anywhere outside of the modal, close it
window.onclick = function (event) {
if (event.target == modal) {
modal.style.display = "none";
}
};
// window.onclick = function (event) {
// if (event.target == modal) {
// modal.style.display = "none";
// }
// };
7 changes: 7 additions & 0 deletions js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
const closeMenuBtn = document.querySelector(".js-close-menu");
const button = document.getElementById("form-btn");
const form = document.getElementById("form");
const menuLinks = document.querySelectorAll(".header-mobile-nav-item a");

const toggleMenu = () => {
const isMenuOpen =
Expand All @@ -21,6 +22,12 @@
form.scrollIntoView({ behavior: "smooth" });
});

menuLinks.forEach((link) => {
link.addEventListener("click", () => {
toggleMenu();
});
});

const anotherButton1 = document.getElementById("form-btn-1");
anotherButton1.addEventListener("click", function () {
form.scrollIntoView({ behavior: "smooth" });
Expand Down

0 comments on commit ec3cc4b

Please sign in to comment.