function easeOutScroll()

in packages/bui-core/src/ScrollView/ScrollView.tsx [8:30]


function easeOutScroll(from, to, callback) {
  if (from === to || typeof from !== 'number') {
    return;
  }
  const change = to - from;
  const dur = 500;
  const sTime = +new Date();
  function linear(t, b, c, d) {
    return (c * t) / d + b;
  }
  const isLarger = to >= from;

  function step() {
    const stepFrom = linear(+new Date() - sTime, from, change, dur);
    if ((isLarger && stepFrom >= to) || (!isLarger && to >= stepFrom)) {
      callback?.(to);
      return;
    }
    callback?.(stepFrom);
    requestAnimationFrame(step);
  }
  step();
}