<template>
<div class="header" :style="style">
</div>
</template>
<script>
export default {
data() {
return {
style: {},
opacity: 0,
}
},
mounted() {
window.addEventListener("scroll", this.windowScroll);
},
methods: {
windowScroll() {
let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
this.opacity = Math.abs(Math.round(scrollTop)) / 250;
this.style = {background: `rgba(0, 0, 0,${this.opacity})`}
},
},
destroyed() {
window.removeEventListener("scroll", this.windowScroll);
}
}
</script>