<template>
<div class="body"></div>
<div v-if="btnShow" style="position: fixed; right: 50px;bottom: 50px; z-index: 2">
<button class="scaleBig" @click="backTop">1213</button>
</div>
</template>
<script>
import { onMounted, ref } from "vue";
export default {
name: "Top",
setup() {
const btnShow = ref(false)
let timer = null; onMounted(() => {
window.addEventListener('scroll', scrollToTop)
})
const backTop=()=> {
timer = setInterval(function () {
let backTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
let speedTop = backTop / 5;
document.documentElement.scrollTop = backTop - speedTop; if (backTop === 0) {
clearInterval(timer)
}
}, 50);
}
const scr
vue3 返回顶部组件
最新推荐文章于 2024-06-14 15:42:03 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)