diff --git a/src/assets/js/nav.js b/src/assets/js/nav.js index 164ad90..f49f5bd 100644 --- a/src/assets/js/nav.js +++ b/src/assets/js/nav.js @@ -4,6 +4,8 @@ class NavBar extends HTMLElement { connectedCallback() { document.addEventListener("scroll", this.onScroll.bind(this)) this.addEventListener('transitionend', this.onTransitionEnd.bind(this)) + this.addEventListener('click', this.onClick.bind(this)) + document.addEventListener('click', this.onDocumentClick.bind(this)) this.onScroll() } @@ -25,6 +27,18 @@ class NavBar extends HTMLElement { this.classList.remove("nav-bar__docking") } } + + onClick(evt) { + if(evt.target.matches('a')) { + this.classList.remove('nav-bar__open') + } + } + + onDocumentClick(evt) { + if(!this.contains(evt.target)) { + this.classList.remove('nav-bar__open') + } + } } class ToggleNavBarButton extends HTMLElement {