@@ -5,14 +5,27 @@ import { Fa } from "../../common/Fa";
55
66export function ScrollToTop ( ) : JSXElement {
77 const [ visible , setVisible ] = createSignal ( false ) ;
8+ const [ scrolling , setScrolling ] = createSignal ( false ) ;
89
910 const handleScroll = ( ) : void => {
10- if ( getActivePage ( ) === "test" ) return ;
11-
11+ if ( getActivePage ( ) === "test" || scrolling ( ) ) return ;
1212 const scroll = window . scrollY ;
1313 setVisible ( scroll > 100 ) ;
1414 } ;
1515
16+ const scrollUp = async ( ) : Promise < void > => {
17+ const scrollEnded = new Promise < void > ( ( resolve ) => {
18+ setTimeout ( resolve , 1000 ) ;
19+ if ( window . scrollY === 0 ) {
20+ resolve ( ) ;
21+ return ;
22+ }
23+ window . addEventListener ( "scrollend" , ( ) => resolve ( ) , { once : true } ) ;
24+ } ) ;
25+ window . scrollTo ( { top : 0 , behavior : "smooth" } ) ;
26+ await scrollEnded ;
27+ } ;
28+
1629 onMount ( ( ) => {
1730 window . addEventListener ( "scroll" , handleScroll , { passive : true } ) ;
1831 handleScroll ( ) ;
@@ -35,12 +48,11 @@ export function ScrollToTop(): JSXElement {
3548 "opacity-0" : getActivePage ( ) === "test" || ! visible ( ) ,
3649 "pointer-events-none" : getActivePage ( ) === "test" || ! visible ( ) ,
3750 } }
38- onClick = { ( ) => {
51+ onClick = { async ( ) => {
3952 setVisible ( false ) ;
40- window . scrollTo ( {
41- top : 0 ,
42- behavior : "smooth" ,
43- } ) ;
53+ setScrolling ( true ) ;
54+ await scrollUp ( ) ;
55+ setScrolling ( false ) ;
4456 } }
4557 >
4658 < Fa icon = "fa-angle-double-up" />
0 commit comments