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(() => {
7474 active .value = window .location .hash || ' #home' ;
7575});
7676
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+
7792function smoothScroll(): void {
7893 document .querySelectorAll <HTMLAnchorElement >(' a[href^="#"]' ).forEach ((anchor ) => {
7994 anchor .addEventListener (' click' , (e : MouseEvent ) => {
8095 e .preventDefault ();
8196
8297 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 ;
8998
90- active .value = hash ;
91-
92- window .location .hash = hash ;
93- window .scrollTo ({ behavior: ' smooth' , top: y });
99+ if (hash ) {
100+ scrollToHash (hash );
94101 }
95102 });
96103 });
104+
105+ window .addEventListener (' load' , () => {
106+ const hash = window .location .hash ;
107+ if (hash ) {
108+ scrollToHash (hash );
109+ }
110+ });
97111}
112+
113+
98114 </script >
99115
100116<style lang="scss">
You can’t perform that action at this time.
0 commit comments