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,