Merge pull request #169 from zpj80231/patch-1
fix($SidebarLinks): fix full path link jump and other questions
This commit is contained in:
commit
3c3c0a99a3
@ -53,7 +53,8 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
mounted () {
|
||||
mounted() {
|
||||
this.activationLink()
|
||||
this.isInViewPortOfOne()
|
||||
},
|
||||
|
||||
@ -62,21 +63,48 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
isInViewPortOfOne () {
|
||||
const 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]
|
||||
activationLink () {
|
||||
let subtitleName = decodeURIComponent(this.$route.fullPath)
|
||||
if (!subtitleName || subtitleName=='') return
|
||||
const subtitles = [].slice.call(document.querySelectorAll(AHL_SIDEBAR_LINK_SELECTOR))
|
||||
for(let i = 0; i < subtitles.length; i++) {
|
||||
if(decodeURIComponent(subtitles[i].getAttribute('href')).indexOf(subtitleName) != -1){
|
||||
subtitles[i].click()
|
||||
this.activationAnchor()
|
||||
return
|
||||
}
|
||||
}
|
||||
if (el === null || el.offsetTop == undefined) return
|
||||
},
|
||||
|
||||
activationAnchor() {
|
||||
let anchors = [].slice.call(document.querySelectorAll(AHL_HEADER_ANCHOR_SELECTOR))
|
||||
.filter(anchor => decodeURIComponent(this.$route.fullPath).indexOf(decodeURIComponent(anchor.hash)) != -1)
|
||||
if(anchors == null || anchors.length<1 || anchors[0].offsetTop == undefined) return
|
||||
setTimeout(function(){
|
||||
window.scrollTo(0, anchors[0].offsetTop + 160)
|
||||
},100)
|
||||
},
|
||||
|
||||
isInViewPortOfOne () {
|
||||
let siderbarScroll = document.getElementsByClassName("sidebar")[0]
|
||||
let el = document.getElementsByClassName("active sidebar-link")[1]
|
||||
if (el ==null || el == undefined || el.offsetTop == undefined) {
|
||||
el = document.getElementsByClassName("active sidebar-link")[0]
|
||||
}
|
||||
if (el ==null || el == undefined || el.offsetTop == undefined) return
|
||||
|
||||
const viewPortHeight = siderbarScroll.clientHeight || window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
|
||||
const offsetBottom = el.offsetTop + el.offsetHeight
|
||||
const scrollTop = siderbarScroll.scrollTop
|
||||
const isView = (offsetBottom <= viewPortHeight + scrollTop)
|
||||
if (!isView) {
|
||||
let offsetTop = el.offsetTop
|
||||
let offsetBottom = el.offsetTop + el.offsetHeight
|
||||
let scrollTop = siderbarScroll.scrollTop
|
||||
let bottomVisible = (offsetBottom <= viewPortHeight + scrollTop)
|
||||
if (!bottomVisible) {
|
||||
siderbarScroll.scrollTop = (offsetBottom + 5 - viewPortHeight)
|
||||
}
|
||||
let topVisible = (offsetTop >= scrollTop)
|
||||
if (!topVisible) {
|
||||
siderbarScroll.scrollTop = (offsetTop - 5)
|
||||
}
|
||||
},
|
||||
|
||||
refreshIndex () {
|
||||
|
Loading…
Reference in New Issue
Block a user