Init Commit
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
const scroll = new SmoothScroll('a[href*="#"]');
|
||||
const navLinks = document.querySelectorAll('a.nav-link');
|
||||
navLinks.forEach(navLink => {
|
||||
navLink.addEventListener('click', (e) => {
|
||||
const navbar = document.getElementById('navbarSupportedContent');
|
||||
if (navbar && navbar.classList.contains('show')) {
|
||||
simulateClick(document.querySelector('.navbar-toggler'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Simulate a click event.
|
||||
* @public
|
||||
* @param {Element} elem the element to simulate a click on
|
||||
* @see https://gomakethings.com/how-to-simulate-a-click-event-with-javascript/
|
||||
*/
|
||||
var simulateClick = function (elem) {
|
||||
// Create our event (with options)
|
||||
var evt = new MouseEvent('click', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
view: window
|
||||
});
|
||||
// If cancelled, don't dispatch our event
|
||||
var canceled = !elem.dispatchEvent(evt);
|
||||
};
|
||||
Reference in New Issue
Block a user