From eaab40895489bc5a8d946b61d37baa2643d6d24c Mon Sep 17 00:00:00 2001 From: huamurui Date: Tue, 13 Jan 2026 21:46:48 +0800 Subject: [PATCH] feat: mobile TOC active highlight --- .../components/VPLocalNavOutlineDropdown.vue | 26 +++- .../theme-default/composables/outline.ts | 147 ++++++++++++++---- 2 files changed, 139 insertions(+), 34 deletions(-) diff --git a/src/client/theme-default/components/VPLocalNavOutlineDropdown.vue b/src/client/theme-default/components/VPLocalNavOutlineDropdown.vue index cf842baa3..7e00b1ec7 100644 --- a/src/client/theme-default/components/VPLocalNavOutlineDropdown.vue +++ b/src/client/theme-default/components/VPLocalNavOutlineDropdown.vue @@ -4,7 +4,7 @@ import { onContentUpdated } from 'vitepress' import type { DefaultTheme } from 'vitepress/theme' import { nextTick, ref, watch } from 'vue' import { useData } from '../composables/data' -import { resolveTitle } from '../composables/outline' +import { resolveTitle, useFloatActiveAnchor } from '../composables/outline' import VPDocOutlineItem from './VPDocOutlineItem.vue' const props = defineProps<{ @@ -17,6 +17,7 @@ const open = ref(false) const vh = ref(0) const main = ref() const items = ref() +const marker = ref() function closeOnClickOutside(e: Event) { if (!main.value?.contains(e.target as Node)) { @@ -61,6 +62,8 @@ function scrollToTop() { open.value = false window.scrollTo({ top: 0, left: 0, behavior: 'smooth' }) } + +useFloatActiveAnchor(items, marker, open)