1- const easeInOutCubic = ( t : number , b : number , c : number , d : number ) => ( t /= d / 2 ) < 1 ? c / 2 * t * t * t + b : c / 2 * ( ( t -= 2 ) * t * t + 2 ) + b ;
1+ const easeInOutCubic = ( t : number , b : number , c : number , d : number ) =>
2+ ( t /= d / 2 ) < 1
3+ ? ( c / 2 ) * t * t * t + b
4+ : ( c / 2 ) * ( ( t -= 2 ) * t * t + 2 ) + b ;
25
3- export function scrollTo ( scrollTo : number , duration : number = 333 ) : Promise < boolean > {
4- const start = ( window . pageYOffset || document . documentElement . scrollTop ) - ( document . documentElement . clientTop || 0 ) ;
6+ export function scrollTo (
7+ scrollTo : number ,
8+ duration : number = 333
9+ ) : Promise < boolean > {
10+ const start =
11+ ( window . pageYOffset || document . documentElement . scrollTop ) -
12+ ( document . documentElement . clientTop || 0 ) ;
513 const change = scrollTo - start ;
614 let previousTime = window . performance . now ( ) ;
715 let currentTime = 0 ;
@@ -12,7 +20,10 @@ export function scrollTo(scrollTo: number, duration: number = 333): Promise<bool
1220 const increment = time - previousTime ;
1321 previousTime = time ;
1422 currentTime += increment ;
15- ( document . scrollingElement || window ) . scrollTo ( 0 , easeInOutCubic ( currentTime , start , change , duration ) ) ;
23+ ( document . scrollingElement || window ) . scrollTo (
24+ 0 ,
25+ easeInOutCubic ( currentTime , start , change , duration )
26+ ) ;
1627
1728 if ( currentTime < duration ) {
1829 return window . requestAnimationFrame ( animateScroll ) ;
@@ -23,4 +34,4 @@ export function scrollTo(scrollTo: number, duration: number = 333): Promise<bool
2334 } ) ;
2435
2536 return ret ;
26- } ;
37+ }
0 commit comments