添加返回顶部组件,优化博客详情页布局和样式,更新Markdown编辑器配置和依赖声明

This commit is contained in:
2025-12-30 21:00:01 +08:00
parent 79192df508
commit d36526b368
7 changed files with 123 additions and 18 deletions

View File

@ -0,0 +1,60 @@
<template>
<div id="goTop">
<div class="icons" v-show="visiable" @click="handleScrollTop">
<n-icon>
<icon-backtop width="60" height="60" />
</n-icon>
</div>
</div>
</template>
<script setup lang="ts">
import { throttle } from 'es-toolkit/function';
const scrollTop: any = ref(null)
const visiable = ref(false)
const scrollElement: any = document.querySelector('.n-scrollbar .n-scrollbar-container')
const handleScroll = throttle(() => {
scrollTop.value = scrollElement.scrollTop
visiable.value = scrollTop.value > 200;
},1000)
function handleScrollTop() {
let timer: any = null;
cancelAnimationFrame(timer);
timer = requestAnimationFrame(function fn() {
if (scrollTop.value > 0) {
scrollTop.value -= 50;
scrollElement.scrollTop = document.documentElement.scrollTop = scrollTop.value;
timer = requestAnimationFrame(fn);
} else {
cancelAnimationFrame(timer);
visiable.value = false;
}
});
}
onMounted(() => {
scrollElement?.addEventListener('scroll', handleScroll);
})
onBeforeMount(() => {
window.removeEventListener('scroll', handleScroll);
})
</script>
<style scoped lang="less">
.icons {
position: fixed;
right: 60px;
bottom: 40px;
border-radius: 50%;
z-index: 9999999;
}
:deep(.n-icon svg) {
width: 30px;
height: 30px;
}
</style>