fix(scroll) highlight bug

This commit is contained in:
qingwei.li 2017-02-19 22:29:35 +08:00
commit 6b08546654
3 changed files with 56 additions and 53 deletions

View file

@ -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 () {
if (isMobile) return
let hoverOver = false
const anchors = dom.findAll('.anchor')
const sidebar = dom.find('.sidebar')
const wrap = dom.find(sidebar, '.sidebar-nav')
const nav = {} const nav = {}
const lis = dom.findAll(sidebar, 'li') let hoverOver = false
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 () { function highlight () {
const sidebar = dom.getNode('.sidebar')
const anchors = dom.findAll('.anchor')
const wrap = dom.find(sidebar, '.sidebar-nav')
let active = dom.find(sidebar, 'li.active')
const top = dom.body.scrollTop const top = dom.body.scrollTop
let last let last
@ -71,6 +53,25 @@ export function scrollActiveSidebar () {
} }
} }
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)
dom.on('scroll', highlight) dom.on('scroll', highlight)
dom.on(sidebar, 'mouseover', () => { hoverOver = true }) dom.on(sidebar, 'mouseover', () => { hoverOver = true })

View file

@ -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)
} }

View file

@ -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...";