fix the sidebar title of beyond the current window that it follows the title of the article in the current window

This commit is contained in:
z 2020-04-05 12:43:55 +08:00 committed by GitHub
parent e6bcfb0176
commit baeec51a43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,