File tree 1 file changed +17
-0
lines changed
src/client/theme-default/composables
1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -117,10 +117,12 @@ export function useActiveAnchor(
117
117
const onScroll = throttleAndDebounce ( setActiveLink , 100 )
118
118
119
119
let prevActiveLink : HTMLAnchorElement | null = null
120
+ let ignoreScrollOnce : boolean = false
120
121
121
122
onMounted ( ( ) => {
122
123
requestAnimationFrame ( setActiveLink )
123
124
window . addEventListener ( 'scroll' , onScroll )
125
+ container . value . addEventListener ( 'click' , onClick )
124
126
} )
125
127
126
128
onUpdated ( ( ) => {
@@ -130,13 +132,28 @@ export function useActiveAnchor(
130
132
131
133
onUnmounted ( ( ) => {
132
134
window . removeEventListener ( 'scroll' , onScroll )
135
+ container . value . removeEventListener ( 'click' , onClick )
133
136
} )
134
137
138
+ function onClick ( e : MouseEvent ) {
139
+ if ( ! isAsideEnabled . value || ! ( e . target instanceof HTMLAnchorElement ) ) {
140
+ return
141
+ }
142
+
143
+ activateLink ( location . hash )
144
+ ignoreScrollOnce = true
145
+ }
146
+
135
147
function setActiveLink ( ) {
136
148
if ( ! isAsideEnabled . value ) {
137
149
return
138
150
}
139
151
152
+ if ( ignoreScrollOnce ) {
153
+ ignoreScrollOnce = false
154
+ return
155
+ }
156
+
140
157
const scrollY = window . scrollY
141
158
const innerHeight = window . innerHeight
142
159
const offsetHeight = document . body . offsetHeight
You can’t perform that action at this time.
0 commit comments