Skip to content

Commit

Permalink
fix($core): remove smoothing scroll (close: #1071) (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcastil authored and ulivz committed Dec 8, 2018
1 parent 3755beb commit 26c0628
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 36 deletions.
10 changes: 9 additions & 1 deletion packages/@vuepress/core/lib/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ export function createApp (isServer) {
base: siteData.base,
mode: 'history',
fallback: false,
routes
routes,
scrollBehavior (to, from, savedPosition) {
if (savedPosition) {
return savedPosition
}
if (to.path !== from.path) {
return { x: 0, y: 0 }
}
}
})

// redirect /foo to /foo/
Expand Down
30 changes: 0 additions & 30 deletions packages/@vuepress/core/lib/app/root-mixins/updateLoadingState.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@
import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js'

export default {
created () {
this.$vuepress.$on('AsyncMarkdownContentMounted', () => {
this.$vuepress.$set('contentMounted', true)

this.$smoothScroll = new SmoothScroll('a[href*="#"]', {
speed: 1,
speedAsDuration: true,
easing: 'easeInOutCubic'
})

if (this.$route.hash) {
const hash = decodeURIComponent(this.$route.hash)
try {
const anchor = document.getElementById(hash.slice(1))
const anchorLink = anchor.querySelector('a.header-anchor')
setTimeout(() => {
window.scroll({
top: anchorLink.offsetTop - 70,
left: 0,
behavior: 'auto'
})
})
} catch (e) {
console.error(e)
}
}
})
},

watch: {
'$route.path' () {
this.$vuepress.$set('contentMounted', false)
this.$smoothScroll.destroy()
}
},

beforeDestroy () {
this.$smoothScroll.destroy()
}
}
1 change: 0 additions & 1 deletion packages/@vuepress/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
"optimize-css-assets-webpack-plugin": "^4.0.0",
"portfinder": "^1.0.13",
"postcss-loader": "^2.1.5",
"smooth-scroll": "^15.0.0",
"toml": "^2.3.3",
"url-loader": "^1.0.1",
"vue": "^2.5.16",
Expand Down
4 changes: 0 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7606,10 +7606,6 @@ slice-ansi@1.0.0:
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"
Expand Down

0 comments on commit 26c0628

Please sign in to comment.