Add automatically close menu whenever theres is a click or scroll event whenever app is in mobile resolution

This commit is contained in:
Afiq Hamzah
2024-04-28 09:15:49 +08:00
parent 53cbd4355f
commit af80391cd3
2 changed files with 20 additions and 0 deletions
+1
View File
@@ -1,4 +1,5 @@
require('./bootstrap.js');
require('./helper/autocloseMenu.js');
//window.VueRouter = require('vue-router').default;
//import VueRouter from 'vue-router';
import Util from './util.js';
+19
View File
@@ -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');
});
}