页面滚动条动画-h5实现

  • Post author:
  • Post category:其他


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;



版权声明:本文为mxm_xixixi原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。