RamEx-Flow / front /src /components /ScrollProgress.vue
zdy10046's picture
add backend code
57528c5
Raw
History Blame Contribute Delete
1.17 kB
<template>
<div class="scroll-progress">
<div class="progress-bar" :style="{ width: `${scrollProgress}%` }"></div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
// 定义组件名称
defineOptions({
name: 'ScrollProgress'
})
const scrollProgress = ref(0)
const updateScrollProgress = () => {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop
const scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight
const progress = (scrollTop / scrollHeight) * 100
scrollProgress.value = Math.min(100, Math.max(0, progress))
}
onMounted(() => {
window.addEventListener('scroll', updateScrollProgress)
updateScrollProgress()
})
onUnmounted(() => {
window.removeEventListener('scroll', updateScrollProgress)
})
</script>
<style scoped>
.scroll-progress {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 4px;
background: rgba(0, 0, 0, 0.1);
z-index: 9999;
}
.progress-bar {
height: 100%;
background: var(--ramex-accent);
transition: width 0.1s ease;
box-shadow: 0 0 10px rgba(102, 126, 234, 0.5);
}
</style>