<template>
<div id="app">
<router-view />
<img
src="../src/images/imgs/footer/up.png"
alt=""
id="return_top"
style="display: block"
/>
</div>
</template>
<script>
export default {
name: "App",
mounted() {
window.onload = function () {
var obtn = document.getElementById("return_top");
var clientHeight = document.documentElement.clientHeight;
var timer = null;
var isTop = true;
window.onscroll = function () {
var osTop =
document.documentElement.scrollTop || document.body.scrollTop;
if (osTop >= clientHeight) {
obtn.style.display = "block";
} else {
obtn.style.display = "none";
}
if (!isTop) {
clearInterval(timer);
}
isTop = false;
};
obtn.onclick = function () {
timer = setInterval(function () {
var osTop =
document.documentElement.scrollTop || document.body.scrollTop;
var speed = Math.floor(-osTop / 6);
document.documentElement.scrollTop = document.body.scrollTop =
osTop + speed;
isTop = true;
if (osTop == 0) {
clearInterval(timer);
}
}, 30);
};
};
},
};
</script>
<style>
* {
margin: 0;
padding: 0;
list-style: none;
font-family: PingFang SC;
}
#return_top {
width: 1rem;
height: 1rem;
position: fixed;
right: 0.1rem;
bottom: 0.1rem;
}
转载请注明原文地址:https://blackberry.8miu.com/read-44281.html