<div id="component-navbar" :class="hasBackground">
computed: {
hasBackground() {
if (window.scrollY > 0) {
return 'has-background'
}
}
}
I am facing an issue with my sticky nav bar where I want to apply a background when the page scroll is greater than 0. The challenge lies in the fact that hasBackground
.
- does not update as the user scrolls
- shows window.scrollY as zero on page reload even after scrolling
- only responds to changes when a file modification triggers hot reload.
How can I resolve this problem?