File tree Expand file tree Collapse file tree 1 file changed +0
-30
lines changed
packages/@vuepress/core/lib/app/root-mixins Expand file tree Collapse file tree 1 file changed +0
-30
lines changed Original file line number Diff line number Diff line change 1
- import SmoothScroll from 'smooth-scroll/dist/smooth-scroll.js'
2
-
3
1
export default {
4
2
created ( ) {
5
3
this . $vuepress . $on ( 'AsyncMarkdownContentMounted' , ( ) => {
6
4
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
- }
30
5
} )
31
6
} ,
32
7
33
8
watch : {
34
9
'$route.path' ( ) {
35
10
this . $vuepress . $set ( 'contentMounted' , false )
36
- this . $smoothScroll . destroy ( )
37
11
}
38
- } ,
39
-
40
- beforeDestroy ( ) {
41
- this . $smoothScroll . destroy ( )
42
12
}
43
13
}
You can’t perform that action at this time.
0 commit comments