From baeec51a43322000042a37845d2b7a0a34948eee Mon Sep 17 00:00:00 2001 From: z <916665067@qq.com> Date: Sun, 5 Apr 2020 12:43:55 +0800 Subject: [PATCH] fix the sidebar title of beyond the current window that it follows the title of the article in the current window --- .../components/SidebarLinks.vue | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/vuepress-theme-reco/components/SidebarLinks.vue b/packages/vuepress-theme-reco/components/SidebarLinks.vue index fe45c6d..f120fd7 100644 --- a/packages/vuepress-theme-reco/components/SidebarLinks.vue +++ b/packages/vuepress-theme-reco/components/SidebarLinks.vue @@ -52,8 +52,33 @@ export default { this.refreshIndex() } }, + + mounted() { + this.isInViewPortOfOne() + }, + + updated: function () { + this.isInViewPortOfOne() + }, methods: { + isInViewPortOfOne () { + let siderbarScroll = document.getElementsByClassName("sidebar")[0] + let el = document.getElementsByClassName("active sidebar-link")[1] + if (el ==null || el.offsetTop == undefined) { + el = document.getElementsByClassName("active sidebar-link")[0] + } + if (el ==null || el.offsetTop == undefined) return + + const viewPortHeight = siderbarScroll.clientHeight || window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight + let offsetBottom = el.offsetTop + el.offsetHeight + let scrollTop = siderbarScroll.scrollTop + let isView = (offsetBottom <= viewPortHeight + scrollTop) + if (!isView) { + siderbarScroll.scrollTop = (offsetBottom+5 - viewPortHeight) + } + }, + refreshIndex () { const index = resolveOpenGroupIndex( this.$route,