export default function smoothScroll()

in src/utils/smoothScroll.ts [17:41]


export default function smoothScroll({ el, to, duration = 300, x }: Props) {
  const attr = x ? 'scrollLeft' : 'scrollTop';

  if (!rAF) {
    el[attr] = to;
    return;
  }

  const from = el[attr];
  const frames = Math.round(duration / 16);
  const step = (to - from) / frames;
  let count = 0;

  function animate() {
    // eslint-disable-next-line no-param-reassign
    el[attr] += step;

    // eslint-disable-next-line no-plusplus
    if (++count < frames) {
      rAF(animate);
    }
  }

  animate();
}