method param { number } top param { boolean } smooth export default function scrollToTarget ( element , target ) { const top = 0 ; const scroller = target ; const easingFn = function easeOutQuad ( t , b , c , d ) { t /= d ; return - c * t * ( t - 2 ) + b ; } ; const animationId = Math . random ( ) ; const duration = 200 ; const startTime = Date . now ( ) ; const currentScrollTop = scroller . scrollTop ; const deltaScrollTop = top - currentScrollTop ; element . _currentAnimationId = animationId ; ( function updateFrame ( ) { const now = Date . now ( ) ; const elapsedTime = now - startTime ; if ( elapsedTime > duration ) { scroller . scrollTop = top ; } else if ( element . _currentAnimationId === animationId ) { scroller . scrollTop = easingFn ( elapsedTime , currentScrollTop , deltaScrollTop , duration ) ; requestAnimationFrame ( updateFrame . bind ( element ) ) ; } } . call ( element ) ) ; }