UNPKG

@fesjs/fes-design

Version:
21 lines (18 loc) 490 B
import { requestAnimationFrame } from './utils'; // 将元素滚动到指定位置 function scrollTo(element, to, duration) { if (duration <= 0) { element.scrollTop = to; return; } const difference = to - element.scrollTop; const perTick = difference / duration * 10; requestAnimationFrame(() => { element.scrollTop += perTick; if (element.scrollTop === to) { return; } scrollTo(element, to, duration - 10); }); } export { scrollTo as default };