scrollTo.ts 500 B

123456789101112131415161718192021
  1. import { Animation } from '@douyinfe/semi-animation';
  2. const scrollTo = (element: HTMLElement, to: number, duration: number) => {
  3. const animation = new Animation(
  4. {
  5. from: { scrollTop: element.scrollTop },
  6. to: { scrollTop: to },
  7. },
  8. { duration }
  9. );
  10. animation.on('frame', ({ scrollTop }: { scrollTop: number }) => {
  11. element.scrollTop = scrollTop;
  12. });
  13. // animation.start();
  14. return animation;
  15. };
  16. export default scrollTo;