diff --git a/CHANGELOG.md b/CHANGELOG.md index eba4cdf6..4553f687 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.1.2 +### Bug fixes +- fix failed `auto2top` in mobile + + ## 1.1.1 ### Bug fixes - Optimize progress bar diff --git a/src/event.js b/src/event.js index 48922fb4..3012b2ac 100644 --- a/src/event.js +++ b/src/event.js @@ -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 } diff --git a/src/render.js b/src/render.js index c85f9362..e1560813 100644 --- a/src/render.js +++ b/src/render.js @@ -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 + '%' } } diff --git a/src/util.js b/src/util.js index 4db56230..013b2769 100644 --- a/src/util.js +++ b/src/util.js @@ -95,3 +95,8 @@ export function getRoute () { return route } + +export function isMobile () { + return /mobile/i.test(navigator.userAgent) +} +