Answer the question
In order to leave comments, you need to log in
How to add the sticky class to the menu while scrolling?
How to add sticky class to menu on scroll using VueJs?
It is necessary to add a menu class when scrolling, so that the menu sticks when scrolling and removed when scrolling to the beginning of the page. How to implement this with VueJs?
window.document.onscroll = () => {
let mobileMenu = document.querySelector('mobile-menu');
if(window.scrollY > mobileMenu.offsetTop){
this.classList.add('sticky')
} else {
this.classList.remove('sticky');
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question