File tree Expand file tree Collapse file tree 1 file changed +26
-10
lines changed
src/documentation/components Expand file tree Collapse file tree 1 file changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -74,27 +74,43 @@ onMounted(() => {
74
74
active .value = window .location .hash || ' #home' ;
75
75
});
76
76
77
+ function scrollToHash(hash : string ): void {
78
+ const id: string = hash .replace (' #' , ' ' );
79
+ const yOffset: number = - 55 ;
80
+ const element: HTMLElement | null = document .getElementById (id );
81
+
82
+ if (element ) {
83
+ const y: number = element .getBoundingClientRect ().top + window .scrollY + yOffset ;
84
+
85
+ active .value = hash ;
86
+
87
+ window .location .hash = hash ;
88
+ window .scrollTo ({ behavior: ' smooth' , top: y });
89
+ }
90
+ }
91
+
77
92
function smoothScroll(): void {
78
93
document .querySelectorAll <HTMLAnchorElement >(' a[href^="#"]' ).forEach ((anchor ) => {
79
94
anchor .addEventListener (' click' , (e : MouseEvent ) => {
80
95
e .preventDefault ();
81
96
82
97
const hash: string = anchor .hash ;
83
- const id: string = hash .replace (' #' , ' ' );
84
- const yOffset: number = - 55 ;
85
- const element: HTMLElement | null = document .getElementById (id );
86
-
87
- if (element ) {
88
- const y: number = element .getBoundingClientRect ().top + window .pageYOffset + yOffset ;
89
98
90
- active .value = hash ;
91
-
92
- window .location .hash = hash ;
93
- window .scrollTo ({ behavior: ' smooth' , top: y });
99
+ if (hash ) {
100
+ scrollToHash (hash );
94
101
}
95
102
});
96
103
});
104
+
105
+ window .addEventListener (' load' , () => {
106
+ const hash = window .location .hash ;
107
+ if (hash ) {
108
+ scrollToHash (hash );
109
+ }
110
+ });
97
111
}
112
+
113
+
98
114
</script >
99
115
100
116
<style lang="scss">
You can’t perform that action at this time.
0 commit comments