吴雨瞳添加了注释

master
wyt 6 months ago
parent 1b43513b18
commit 2dc6c095b2

@ -1,56 +1,77 @@
<template>
<!-- 侧边导航组件容器使用flex布局深色背景带圆角和阴影效果 -->
<ul
id="sidebar-navigator"
class="flex flex-row bg-ob-deep-800 rounded-xl shadow-2xl justify-items-center overflow-hidden">
id="sidebar-navigator"
class="flex flex-row bg-ob-deep-800 rounded-xl shadow-2xl justify-items-center overflow-hidden">
<!-- 返回按钮点击触发返回上一页功能带右边框和悬停效果 -->
<li
class="border-r-4 border-ob-deep-900 flex justify-center py-3 w-full hover:opacity-50 hover:text-ob transition-all cursor-pointer"
@click="goBack">
class="border-r-4 border-ob-deep-900 flex justify-center py-3 w-full hover:opacity-50 hover:text-ob transition-all cursor-pointer"
@click="goBack">
<svg-icon class="inline-block text-3xl" icon-class="go-back" />
</li>
<!-- 返回顶部按钮点击触发滚动到页面顶部功能带右边框和悬停效果 -->
<li
class="border-r-4 border-ob-deep-900 flex justify-center py-3 w-full hover:opacity-50 hover:text-ob transition-all cursor-pointer"
@click="toPageTop">
class="border-r-4 border-ob-deep-900 flex justify-center py-3 w-full hover:opacity-50 hover:text-ob transition-all cursor-pointer"
@click="toPageTop">
<svg-icon class="inline-block text-3xl" icon-class="back-to-top" />
</li>
<!-- 跳转到评论区按钮点击滚动到评论区域带悬停效果 -->
<li
class="flex justify-center py-3 w-full hover:opacity-50 hover:text-ob transition-all cursor-pointer"
@click="jumpToComments"
data-dia="jump-to-comment">
class="flex justify-center py-3 w-full hover:opacity-50 hover:text-ob transition-all cursor-pointer"
@click="jumpToComments"
data-dia="jump-to-comment">
<svg-icon class="inline-block text-3xl" icon-class="quote" />
</li>
</ul>
</template>
<script lang="ts">
// Vue
import { defineComponent, ref } from 'vue'
//
import { useRouter } from 'vue-router'
//
export default defineComponent({
name: 'Example',
setup() {
//
const router = useRouter()
//
const commentOffset = ref(0)
// DOM
const commentEl = ref()
// 使
const toPageTop = () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
})
}
// back
const goBack = () => {
router.back()
}
//
const jumpToComments = () => {
// id'comments'DOM
commentEl.value = document.getElementById('comments')
if (commentEl.value) {
// + 120px - 30px
commentOffset.value =
commentEl.value && commentEl.value instanceof HTMLElement ? commentEl.value.offsetTop + 120 - 30 : 0
commentEl.value && commentEl.value instanceof HTMLElement ? commentEl.value.offsetTop + 120 - 30 : 0
}
// 使
window.scrollTo({
top: commentOffset.value,
behavior: 'smooth'
})
}
// 使
return {
goBack,
toPageTop,
@ -62,8 +83,9 @@ export default defineComponent({
<style lang="scss" scoped>
#sidebar-navigator {
// SVGli
svg {
pointer-events: none;
}
}
</style>
</style>
Loading…
Cancel
Save