const scrollAnimation = (
dom = document.documentElement,
currentY: number,
targetY: number,
) => {
let requestId:number
let needScrollTop = targetY – currentY;
let _currentY = currentY;
const scrollAnimate =()=>{
const dist = Math.ceil(needScrollTop / 10);
if (Math.abs(_currentY – targetY) < 10) {
dom.scrollTop = targetY;
return cancelAnimationFrame(requestId)
}
_currentY += dist;
dom.scrollTop = _currentY;
requestId = requestAnimationFrame(scrollAnimate)
}
requestId = requestAnimationFrame(scrollAnimate)
};
export default scrollAnimation;