Add automatically close menu whenever theres is a click or scroll event whenever app is in mobile resolution
This commit is contained in:
+19
@@ -0,0 +1,19 @@
|
||||
|
||||
if (window.innerWidth <= 768) {
|
||||
window.addEventListener('click', function (event) {
|
||||
const navbarCollapse = document.getElementById('myNavbar');
|
||||
|
||||
if (!event.target.matches('.navbar-toggler')) {
|
||||
navbarCollapse.classList.remove('in');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Close navbar when scrolling
|
||||
window.addEventListener('scroll', function () {
|
||||
const navbarCollapse = document.getElementById('myNavbar');
|
||||
|
||||
navbarCollapse.classList.remove('in');
|
||||
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user