vue 返回顶部
<template>
<div>
<div style="
height: 600px;
padding: 10px;
overflow-y: auto;
overflow-x: hidden;
"
@scroll="myFunction($event)">
<div id="arrowup">
...
</div>
</div>
<!-- 返回顶部 ref获取元素-->
<div id="UP" ref="refUP" v-show="isShow">
<a href="#arrowup">
<a-icon style="fontSize:50px;color:" type="arrow-up" />
</a>
</div>
</div>
</template>
<script>
export default {
data(){
return {
isShow:false,
}
}
methods: {
myFunction(e) {
if(e.srcElement.scrollTop > 100){
this.isShow=true
}else{
this.isShow=false
}
},
}
}
</script>
<style scoped>
#UP{
display: none;
background-color: rgba(0, 0, 0, 0.1);
border-radius: 50%;
width: 50px;
height: 50px;
position:fixed;
left: 90%;
bottom: 150px;
display: flex;
align-items: center;
justify-content: center;
}
</style>