Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const step = () => {
scrollTop(target, top > nextTop ? nextTop : top);
if (top <= nextTop) {
requestAnimationFramePolyfill(step);
}
callback?.(top);
top += 20;
};
if (animation) {
target: Element,
nextTop: number,
animation = true,
callback?: (top: number) => void
) {
let top = scrollTop(target);
const step = () => {
scrollTop(target, top > nextTop ? nextTop : top);
if (top <= nextTop) {
requestAnimationFramePolyfill(step);
}
callback?.(top);
top += 20;
};
if (animation) {
requestAnimationFramePolyfill(step);
} else {
scrollTop(target, nextTop);
}
}