Struggling to add and remove a class from the header on scroll without success. The class is currently being added multiple times with each scroll, resulting in duplication. How can I ensure the class is only added once and removed when ScrollY < 100?
What mistake am I making in my code implementation?
<div id="app">
<v-app>
<v-content>
<v-container fluid fill-height class="priceContainer">
<v-layout row wrap align-center justify-center>
<v-flex xs12 sm12 text-center>
<v-toolbar
:clipped-left="$vuetify.breakpoint.lgAndUp"
class="elevation-0 "
fixed
temporary
@scroll="handleSCroll"
>
<v-toolbar-side-icon @click.stop="drawer = !drawer" ></v-toolbar-side-icon>
<v-toolbar-title style="width: 300px" class="ml-0 pl-3">
<span class="PriceLogoTitle hidden-sm-and-up">ELS</span>
<span class="PriceLogoTitle hidden-sm-and-down">ELS</span>
</v-toolbar-title>
<v-spacer></v-spacer>
<!-- Login button -->
<v-btn class="navBtnEnter" flat>Enter <v-icon right >account_box</v-icon></v-btn>
<!-- End of login button -->
</v-toolbar>
</v-flex>
</v-layout>
</v-container>
</v-content>
</v-app>
</div>
.priceContainer{
background-image: radial-gradient( rgb(3, 237, 245),rgb(0, 126, 131));
height: 1000px;
}
.theme--light.v-toolbar--bgchange {
background-color: #009D95;
}
new Vue({
el: '#app',
methods:{
handleSCroll (event) {
let header = document.querySelector(".v-toolbar");
if (window.scrollY > 100) {
console.log(window.scrollY);
header.className += " v-toolbar--bgchange";
}
}
},
created () {
window.addEventListener('scroll', this.handleSCroll);
},
destroyed () {
window.removeEventListener('scroll', this.handleSCroll);
}
})