用法
throttle 函数用于节流处理,在指定时间内多次触发只执行第一次。
import { throttle } from '@movk/core'
const throttledScroll = throttle((event: Event) => {
console.log('滚动事件处理')
}, 100)
// 监听滚动事件,每100ms最多执行一次
window.addEventListener('scroll', throttledScroll)
API
throttle<T>(func, limit)
节流函数,在指定时间内多次触发只执行第一次。
参数
func
T extends (...args: any[]) => any required
需要节流的函数。
limit
number required
节流时间间隔(毫秒)。
返回值
返回值
(...args: Parameters<T>) => void
节流处理后的函数。
Changelog
No recent changes