Hi there! I'm currently in the final stages of polishing up my website before launching it online. However, I'm stuck on how to add an eventListener that will close the navbar hamburger menu without requiring manual scrolling back up to the top of the landing page. Here's what I've got so far.
//Function to select an element
const selectElement = function (element) {
return document.querySelector(element);
};
let menuToggler = selectElement('.menu-toggle');
let body = selectElement('body');
menuToggler.addEventListener('click', function () {
body.classList.toggle('open');
});
// Implementing a parallax scrolling effect
window.addEventListener('scroll', function () {
const parallax = document.querySelector('.parallax');
let scrollPosition = window.pageYOffset;
parallax.style.transform = 'translateY(' + scrollPosition * -.10 + 'px)';
});
For more context, here's a screenshot of the HTML document with the nav tag. I would greatly appreciate a detailed explanation of the JavaScript code as I am still relatively new to it. : ) Thank you! https://i.sstatic.net/4XI2l.png
I've also included a link to a video showcasing how the hamburger menu functions