Answer the question
In order to leave comments, you need to log in
Why doesn't the body scroll check work correctly?
<template>
<div :class="{ 'full-height': checkRouteName }" id="app">
<header class="header">
<div class="container">
<div class="header__row">
<router-link to="/">
<img src="@/assets/img/logo.svg" alt="Triangle" />
</router-link>
<nav class="menu">
<li class="menu__item">
<router-link to="/" class="menu__link" active-class="active" exact
>Home</router-link
>
</li>
<li class="menu__item">
<router-link to="/news" class="menu__link" active-class="active"
>News</router-link
>
</li>
<li class="menu__item">
<router-link to="/bands" class="menu__link" active-class="active"
>Bands</router-link
>
</li>
<li class="menu__item">
<router-link to="/media" class="menu__link" active-class="active"
>Media</router-link
>
</li>
</nav>
<button class="hamburger"></button>
</div>
</div>
</header>
<router-view />
<button
class="scroll"
:class="{ visible: checkScroll }"
id="scroll"
></button>
</div>
</template>
<script>
export default {
methods: {
checkScroll() {
return document.body.scrollTop > 0;
}
},
computed: {
checkRouteName() {
return this.$route.name == "Home";
}
}
};
</script>
Answer the question
In order to leave comments, you need to log in
does not work correctly
data: () => ({
scroll: 0,
}),
computed: {
buttonClass() {
return что-то, зависящее от значения this.scroll;
},
},
created() {
const { body } = document;
const onScroll = () => this.scroll = body.scrollTop;
body.addEventListener('scroll', onScroll);
this.$on('hook:beforeDestroy', () => body.removeEventListener('scroll', onScroll));
},
<button :class="buttonClass"></button>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question