// 缓动到某位置 export default function linearScrollTo(yAxis, duration = 500){ const startTime = +new Date(); const oTop = window.pageYOffset; const dis = yAxis - oTop; let timer = requestAnimationFrame(function func() { const t = duration - Math.max(0, startTime + duration - (+new Date())); window.scrollTo(0, t * dis / duration + oTop) timer = requestAnimationFrame(func); if (t === duration) { cancelAnimationFrame(timer); } }); }