mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-13 17:05:47 +08:00
25bebce59d
* feat(components): anchor component * fix(components): [anchor] marker opacity style * test(components): [anchor] update snapshots * fix(components): [anchor] style change and add version tag * docs(components): [anchor] affix mode demo add affix offset * fix(components): [anchor] change api * fix: slot name change * fix: scrollTo method change * fix: delete getCurrentAnchor api * style: text overflow * docs: change toc to anchor * refactor: useEventListener * fix: update * fix: update
23 lines
352 B
TypeScript
23 lines
352 B
TypeScript
import { cAF, rAF } from './raf'
|
|
|
|
export function throttleByRaf(cb: (...args: any[]) => void) {
|
|
let timer = 0
|
|
|
|
const throttle = (...args: any[]): void => {
|
|
if (timer) {
|
|
cAF(timer)
|
|
}
|
|
timer = rAF(() => {
|
|
cb(...args)
|
|
timer = 0
|
|
})
|
|
}
|
|
|
|
throttle.cancel = () => {
|
|
cAF(timer)
|
|
timer = 0
|
|
}
|
|
|
|
return throttle
|
|
}
|