Skip to content

Commit 26c0628

Browse files
dcastilulivz
authored andcommitted
fix($core): remove smoothing scroll (close: #1071) (#1075)
1 parent 3755beb commit 26c0628

File tree

4 files changed

+9
-36
lines changed

4 files changed

+9
-36
lines changed

packages/@vuepress/core/lib/app/app.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,15 @@ export function createApp (isServer) {
6262
base: siteData.base,
6363
mode: 'history',
6464
fallback: false,
65-
routes
65+
routes,
66+
scrollBehavior (to, from, savedPosition) {
67+
if (savedPosition) {
68+
return savedPosition
69+
}
70+
if (to.path !== from.path) {
71+
return { x: 0, y: 0 }
72+
}
73+
}
6674
})
6775

6876
// redirect /foo to /foo/
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,13 @@
1-
import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js'
2-
31
export default {
42
created () {
53
this.$vuepress.$on('AsyncMarkdownContentMounted', () => {
64
this.$vuepress.$set('contentMounted', true)
7-
8-
this.$smoothScroll = new SmoothScroll('a[href*="#"]', {
9-
speed: 1,
10-
speedAsDuration: true,
11-
easing: 'easeInOutCubic'
12-
})
13-
14-
if (this.$route.hash) {
15-
const hash = decodeURIComponent(this.$route.hash)
16-
try {
17-
const anchor = document.getElementById(hash.slice(1))
18-
const anchorLink = anchor.querySelector('a.header-anchor')
19-
setTimeout(() => {
20-
window.scroll({
21-
top: anchorLink.offsetTop - 70,
22-
left: 0,
23-
behavior: 'auto'
24-
})
25-
})
26-
} catch (e) {
27-
console.error(e)
28-
}
29-
}
305
})
316
},
327

338
watch: {
349
'$route.path' () {
3510
this.$vuepress.$set('contentMounted', false)
36-
this.$smoothScroll.destroy()
3711
}
38-
},
39-
40-
beforeDestroy () {
41-
this.$smoothScroll.destroy()
4212
}
4313
}

packages/@vuepress/core/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"optimize-css-assets-webpack-plugin": "^4.0.0",
5656
"portfinder": "^1.0.13",
5757
"postcss-loader": "^2.1.5",
58-
"smooth-scroll": "^15.0.0",
5958
"toml": "^2.3.3",
6059
"url-loader": "^1.0.1",
6160
"vue": "^2.5.16",

yarn.lock

-4
Original file line numberDiff line numberDiff line change
@@ -7606,10 +7606,6 @@ [email protected]:
76067606
dependencies:
76077607
is-fullwidth-code-point "^2.0.0"
76087608

7609-
smooth-scroll@^15.0.0:
7610-
version "15.0.0"
7611-
resolved "https://registry.yarnpkg.com/smooth-scroll/-/smooth-scroll-15.0.0.tgz#be4f9cb2cc4952d80db6736e5656ed5849305272"
7612-
76137609
snapdragon-node@^2.0.1:
76147610
version "2.1.1"
76157611
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"

0 commit comments

Comments
 (0)