vue——点击置顶
// 再在想监听滚动的父容器绑定上id名
<div class="download" id="scrollBlock">
<div class="toTop" @click="totop" v-show="toTop">
<img src="../../assets/img/homeTop.png" alt="" srcset="">
</div>
</div>
data() {
return {
toTop: false,
};
},
methods: {
handleScroll() {
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop
console.log(scrollTop)
if (scrollTop > 200) {
this.toTop = true
} else {
this.toTop = false
}
},
totop() {
document.documentElement.scrollTop = 0
document.body.scrollTop = 0
},
}