修改回到顶部的显示隐藏问题
This commit is contained in:
parent
385d8e34c5
commit
f07f6586b2
@ -1,10 +1,12 @@
|
||||
<template>
|
||||
<div class="returnTop flexcenter" @click="screenroll()">
|
||||
<div class="returnTop flexcenter" @click="screenroll()" v-if="show">
|
||||
<img class="icon" src="@/assets/img/publicImage/back-icon.png">
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { onMounted, onUnmounted, ref } from 'vue'
|
||||
let show = ref(false)
|
||||
onMounted(() => {
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
});
|
||||
@ -15,17 +17,9 @@ onUnmounted(() => {
|
||||
|
||||
const handleScroll = () => {
|
||||
if (Math.random() > 0.3) return
|
||||
// for (let i = 0; i < navList.value.length; i++) {
|
||||
// let element = navList.value[i]
|
||||
|
||||
// const rect = eval(element.value).value.getBoundingClientRect();
|
||||
// const distanceToTop = rect.top;
|
||||
// if (distanceToTop >= 0) {
|
||||
// navTab.value = element.value
|
||||
// break;
|
||||
// }
|
||||
|
||||
// }
|
||||
const scrolledDistance = window.scrollY || window.pageYOffset;
|
||||
if (scrolledDistance >= 500 && !show.value) show.value = true
|
||||
if (scrolledDistance < 500 && show.value) show.value = false
|
||||
}
|
||||
|
||||
const screenroll = () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user