Reputation: 223
I'm trying to achieve a navigation bar that has initial styling but at the end of a specific container, I'm wanting to update the styling of the navigation bar.
<template>
<div style="position:fixed" class="mynav" ref="desktop">
content..
</div>
</template>
mounted () {
window.document.body.onscroll = () => {
console.log(this.$refs.desktop.scrollHeight)
}
}
but the scrollHeight is always the same. How can I figure out where the position:fixed element is located at on window scroll?
Upvotes: 1
Views: 1967
Reputation: 474
try this :
<template>
<div class="container-body" @mousewheel="handelScroll">
<div style="position:fixed" class="mynav" ref="desktop">
content..
</div>
</div>
</template>
<script>
handelScroll(){
let scrollDiv = document.getElementsByClassName('mynav')
console.log(scrollDiv)
if(window.scrollY < 100){
console.log(window.scrollY , scrollDiv)
scrollDiv[0].classList.add('updateClass')
}
else{
scrollDiv[0].classList.remove('updateClass')
}
}
</script>
<style>
.updateClass{
display:none;
}
</style>
Upvotes: 3