File tree 4 files changed +18
-27
lines changed
4 files changed +18
-27
lines changed Original file line number Diff line number Diff line change @@ -62,21 +62,7 @@ export function createApp (isServer) {
62
62
base : siteData . base ,
63
63
mode : 'history' ,
64
64
fallback : false ,
65
- routes,
66
- scrollBehavior : ( to , from , saved ) => {
67
- if ( saved ) {
68
- return saved
69
- } else if ( to . hash ) {
70
- if ( Vue . $vuepress . $get ( 'disableScrollBehavior' ) ) {
71
- return false
72
- }
73
- return {
74
- selector : to . hash
75
- }
76
- } else {
77
- return { x : 0 , y : 0 }
78
- }
79
- }
65
+ routes
80
66
} )
81
67
82
68
// redirect /foo to /foo/
Original file line number Diff line number Diff line change
1
+ import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js'
2
+
1
3
export default {
2
4
created ( ) {
3
5
this . $vuepress . $on ( 'AsyncMarkdownContentMounted' , ( ) => {
4
- this . $vuepress . $set ( 'contentMounted' , true ) ;
6
+ this . $vuepress . $set ( 'contentMounted' , true )
5
7
6
- [ ] . slice . call ( document . querySelectorAll ( 'a[href^="#"]' ) ) . forEach ( anchor => {
7
- anchor . addEventListener ( 'click' , function ( e ) {
8
- e . preventDefault ( )
9
- history . pushState ( history . state , document . title , e . target . href )
10
- window . scroll ( {
11
- top : e . target . offsetTop - 75 ,
12
- left : 0 ,
13
- behavior : 'smooth'
14
- } )
15
- } )
8
+ this . $smoothScroll = new SmoothScroll ( 'a[href*="#"]' , {
9
+ speed : 1000 ,
10
+ easing : 'easeInOutCubic'
16
11
} )
17
12
18
13
if ( this . $route . hash ) {
@@ -37,6 +32,11 @@ export default {
37
32
watch : {
38
33
'$route.path' ( ) {
39
34
this . $vuepress . $set ( 'contentMounted' , false )
35
+ this . $smoothScroll . destroy ( )
40
36
}
37
+ } ,
38
+
39
+ beforeDestroy ( ) {
40
+ this . $smoothScroll . destroy ( )
41
41
}
42
42
}
Original file line number Diff line number Diff line change 68
68
"webpack-chain" : " ^4.6.0" ,
69
69
"webpack-merge" : " ^4.1.2" ,
70
70
"webpack-serve" : " ^1.0.2" ,
71
- "webpackbar" : " ^2.6.1"
71
+ "webpackbar" : " ^2.6.1" ,
72
+ "smooth-scroll" : " ^15.0.0"
72
73
},
73
74
"engines" : {
74
75
"node" : " >=8"
Original file line number Diff line number Diff line change 8119
8119
dependencies :
8120
8120
is-fullwidth-code-point "^2.0.0"
8121
8121
8122
+ smooth-scroll@^15.0.0 :
8123
+ version "15.0.0"
8124
+ resolved "https://registry.yarnpkg.com/smooth-scroll/-/smooth-scroll-15.0.0.tgz#be4f9cb2cc4952d80db6736e5656ed5849305272"
8125
+
8122
8126
snapdragon-node@^2.0.1 :
8123
8127
version "2.1.1"
8124
8128
resolved "https://registry.yarnpkg.com/snapdragon-node/-/snapdragon-node-2.1.1.tgz#6c175f86ff14bdb0724563e8f3c1b021a286853b"
You can’t perform that action at this time.
0 commit comments