-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,21 +62,7 @@ export function createApp (isServer) { | |
base: siteData.base, | ||
mode: 'history', | ||
fallback: false, | ||
routes, | ||
scrollBehavior: (to, from, saved) => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
ulivz
Author
Member
|
||
if (saved) { | ||
return saved | ||
} else if (to.hash) { | ||
if (Vue.$vuepress.$get('disableScrollBehavior')) { | ||
return false | ||
} | ||
return { | ||
selector: to.hash | ||
} | ||
} else { | ||
return { x: 0, y: 0 } | ||
} | ||
} | ||
routes | ||
}) | ||
|
||
// redirect /foo to /foo/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,13 @@ | ||
import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js' | ||
|
||
export default { | ||
created () { | ||
this.$vuepress.$on('AsyncMarkdownContentMounted', () => { | ||
this.$vuepress.$set('contentMounted', true); | ||
this.$vuepress.$set('contentMounted', true) | ||
|
||
[].slice.call(document.querySelectorAll('a[href^="#"]')).forEach(anchor => { | ||
anchor.addEventListener('click', function (e) { | ||
e.preventDefault() | ||
history.pushState(history.state, document.title, e.target.href) | ||
window.scroll({ | ||
top: e.target.offsetTop - 75, | ||
left: 0, | ||
behavior: 'smooth' | ||
}) | ||
}) | ||
this.$smoothScroll = new SmoothScroll('a[href*="#"]', { | ||
speed: 1000, | ||
This comment has been minimized.
Sorry, something went wrong.
spiltcoffee
Contributor
|
||
easing: 'easeInOutCubic' | ||
}) | ||
|
||
if (this.$route.hash) { | ||
|
@@ -37,6 +32,11 @@ export default { | |
watch: { | ||
'$route.path' () { | ||
this.$vuepress.$set('contentMounted', false) | ||
this.$smoothScroll.destroy() | ||
} | ||
}, | ||
|
||
beforeDestroy () { | ||
this.$smoothScroll.destroy() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8119,6 +8119,10 @@ [email protected]: | |
dependencies: | ||
is-fullwidth-code-point "^2.0.0" | ||
|
||
smooth-scroll@^15.0.0: | ||
version "15.0.0" | ||
resolved "https://registry.yarnpkg.com/smooth-scroll/-/smooth-scroll-15.0.0.tgz#be4f9cb2cc4952d80db6736e5656ed5849305272" | ||
|
||
snapdragon-node@^2.0.1: | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b" | ||
|
@ulivz Was it intended to remove scrollBehavior completely? I now miss the scroll-to-top behavior when navigating between routes in the latest alpha.