Fix auto2top in mobile

This commit is contained in:
qingwei.li 2016-12-17 15:08:44 +08:00
parent aa1d84b513
commit 299c31dff9
4 changed files with 21 additions and 6 deletions

View File

@ -1,3 +1,8 @@
## 1.1.2
### Bug fixes
- fix failed `auto2top` in mobile
## 1.1.1
### Bug fixes
- Optimize progress bar

View File

@ -1,10 +1,11 @@
import { isMobile } from './util'
/**
* Active sidebar when scroll
* @link https://buble.surge.sh/
*/
export function scrollActiveSidebar () {
if (/mobile/i.test(navigator.userAgent)) return
if (isMobile()) return
const anchors = document.querySelectorAll('.anchor')
const nav = {}
@ -92,7 +93,10 @@ export function bindToggle (dom) {
}
let cacheContentDOM
export function scroll2Top (dom) {
cacheContentDOM = cacheContentDOM || document.querySelector(dom)
export function scroll2Top () {
if (!cacheContentDOM) {
const dom = isMobile() ? 'body' : 'section.content'
cacheContentDOM = document.querySelector(dom)
}
cacheContentDOM.scrollTop = 0
}

View File

@ -70,7 +70,7 @@ export function renderArticle (content) {
renderSidebar.rendered = false
renderNavbar.rendered = false
if (OPTIONS.auto2top) scroll2Top('section.content')
if (OPTIONS.auto2top) scroll2Top()
}
/**
@ -123,14 +123,15 @@ export function renderLoading ({ loaded, total }) {
CACHE['loading'] = div
}
CACHE['loading'].style.opacity = 1
CACHE['loading'].style.width = num + '%'
if (num >= 95) {
clearTimeout(renderLoading.cacheTImeout)
renderLoading.cacheTImeout = setTimeout(_ => {
CACHE['loading'].style.opacity = 0
CACHE['loading'].style.width = '0%'
}, 200)
} else {
CACHE['loading'].style.opacity = 1
CACHE['loading'].style.width = num + '%'
}
}

View File

@ -95,3 +95,8 @@ export function getRoute () {
return route
}
export function isMobile () {
return /mobile/i.test(navigator.userAgent)
}