mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-16 01:29:11 +08:00
be92498f15
* fix * test * Update index.ts * fix * fix * fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * fix: fix * update docs * Update components/affix/index.tsx Co-authored-by: kiner-tang(文辉) <1127031143@qq.com> Signed-off-by: lijianan <574980606@qq.com> * fix * test: add test case * Update components/affix/index.zh-CN.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> * update demo --------- Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: kiner-tang(文辉) <1127031143@qq.com> Co-authored-by: afc163 <afc163@gmail.com>
26 lines
494 B
TypeScript
26 lines
494 B
TypeScript
import raf from 'rc-util/lib/raf';
|
|
|
|
function throttleByAnimationFrame<T extends any[]>(fn: (...args: T) => void) {
|
|
let requestId: number | null;
|
|
|
|
const later = (args: T) => () => {
|
|
requestId = null;
|
|
fn(...args);
|
|
};
|
|
|
|
const throttled = (...args: T) => {
|
|
if (requestId == null) {
|
|
requestId = raf(later(args));
|
|
}
|
|
};
|
|
|
|
throttled.cancel = () => {
|
|
raf.cancel(requestId!);
|
|
requestId = null;
|
|
};
|
|
|
|
return throttled;
|
|
}
|
|
|
|
export default throttleByAnimationFrame;
|