File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -78,10 +78,12 @@ class Sidebar {
78
78
}
79
79
80
80
setActiveLink ( section ) {
81
- if ( this . activeLink ) {
81
+ let sectionSelected = this . activeLink ?. href . split ( '#' ) [ 1 ] === section ?. id ;
82
+ if ( this . activeLink && ! sectionSelected ) {
82
83
this . activeLink . parentElement . classList . remove ( 'active' ) ;
83
84
}
84
- if ( section ) {
85
+
86
+ if ( section && ! sectionSelected ) {
85
87
this . activeLink = document . querySelector ( `#sidebar a[href="#${ section . id } "]` ) ;
86
88
if ( this . activeLink ) {
87
89
let headingChildren = this . activeLink . parentElement . parentElement ;
@@ -90,8 +92,18 @@ class Sidebar {
90
92
if ( heading && headingChildren . style . display === 'none' ) {
91
93
this . activeLink = heading ;
92
94
}
95
+
93
96
this . activeLink . parentElement . classList . add ( 'active' ) ;
94
- this . activeLink . parentElement . scrollIntoView ( { block : 'nearest' , inline : 'start' } ) ;
97
+ //this.setTimeout = window.setTimeout.bind(window);
98
+ //this.clearTimeout = window.clearTimeout.bind(window);
99
+ let scrollToActiveLink = ( activeLink ) => {
100
+ activeLink . parentElement . scrollIntoView ( { block : 'nearest' , inline : 'nearest' , behavior : 'auto' } ) ;
101
+ }
102
+ setTimeout (
103
+ scrollToActiveLink ,
104
+ 200 ,
105
+ this . activeLink
106
+ ) ;
95
107
}
96
108
}
97
109
}
You can’t perform that action at this time.
0 commit comments