fix(scroll) highlight bug
This commit is contained in:
parent
46ff5e14bf
commit
6b08546654
3 changed files with 56 additions and 53 deletions
|
|
@ -2,32 +2,14 @@ import { isMobile } from '../util/env'
|
||||||
import * as dom from '../util/dom'
|
import * as dom from '../util/dom'
|
||||||
import { parse } from '../route/hash'
|
import { parse } from '../route/hash'
|
||||||
|
|
||||||
export function scrollActiveSidebar () {
|
const nav = {}
|
||||||
if (isMobile) return
|
let hoverOver = false
|
||||||
|
|
||||||
let hoverOver = false
|
function highlight () {
|
||||||
|
const sidebar = dom.getNode('.sidebar')
|
||||||
const anchors = dom.findAll('.anchor')
|
const anchors = dom.findAll('.anchor')
|
||||||
const sidebar = dom.find('.sidebar')
|
|
||||||
const wrap = dom.find(sidebar, '.sidebar-nav')
|
const wrap = dom.find(sidebar, '.sidebar-nav')
|
||||||
|
|
||||||
const nav = {}
|
|
||||||
const lis = dom.findAll(sidebar, 'li')
|
|
||||||
let active = dom.find(sidebar, 'li.active')
|
let active = dom.find(sidebar, 'li.active')
|
||||||
|
|
||||||
for (let i = 0, len = lis.length; i < len; i += 1) {
|
|
||||||
const li = lis[i]
|
|
||||||
const a = li.querySelector('a')
|
|
||||||
if (!a) continue
|
|
||||||
let href = a.getAttribute('href')
|
|
||||||
|
|
||||||
if (href !== '/') {
|
|
||||||
href = parse(href).query.id
|
|
||||||
}
|
|
||||||
|
|
||||||
nav[decodeURIComponent(href)] = li
|
|
||||||
}
|
|
||||||
|
|
||||||
function highlight () {
|
|
||||||
const top = dom.body.scrollTop
|
const top = dom.body.scrollTop
|
||||||
let last
|
let last
|
||||||
|
|
||||||
|
|
@ -69,6 +51,25 @@ export function scrollActiveSidebar () {
|
||||||
|
|
||||||
sidebar.scrollTop = top
|
sidebar.scrollTop = top
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function scrollActiveSidebar () {
|
||||||
|
if (isMobile) return
|
||||||
|
|
||||||
|
const sidebar = dom.getNode('.sidebar')
|
||||||
|
const lis = dom.findAll(sidebar, 'li')
|
||||||
|
|
||||||
|
for (let i = 0, len = lis.length; i < len; i += 1) {
|
||||||
|
const li = lis[i]
|
||||||
|
const a = li.querySelector('a')
|
||||||
|
if (!a) continue
|
||||||
|
let href = a.getAttribute('href')
|
||||||
|
|
||||||
|
if (href !== '/') {
|
||||||
|
href = parse(href).query.id
|
||||||
|
}
|
||||||
|
|
||||||
|
nav[decodeURIComponent(href)] = li
|
||||||
}
|
}
|
||||||
|
|
||||||
dom.off('scroll', highlight)
|
dom.off('scroll', highlight)
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,12 @@ function renderMain (html) {
|
||||||
// execute script
|
// execute script
|
||||||
this.config.executeScript && executeScript()
|
this.config.executeScript && executeScript()
|
||||||
|
|
||||||
if (!this.config.executeScript &&
|
if (this.config.executeScript !== false &&
|
||||||
typeof window.Vue !== 'undefined' &&
|
typeof window.Vue !== 'undefined' &&
|
||||||
!executeScript()) {
|
!executeScript()) {
|
||||||
setTimeout(_ => {
|
setTimeout(_ => {
|
||||||
|
const vueVM = window.__EXECUTE_RESULT__
|
||||||
|
vueVM && vueVM.$destroy && vueVM.$destroy()
|
||||||
window.__EXECUTE_RESULT__ = new window.Vue().$mount('#main')
|
window.__EXECUTE_RESULT__ = new window.Vue().$mount('#main')
|
||||||
}, 0)
|
}, 0)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ div#app {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 30px;
|
font-size: 30px;
|
||||||
font-weight: lighter;
|
font-weight: lighter;
|
||||||
margin: 40vw auto;
|
margin: 40vh auto;
|
||||||
|
|
||||||
&:empty::before {
|
&:empty::before {
|
||||||
content: "Loading...";
|
content: "Loading...";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue