防止重复点击

/**
 * 防止重覆点击
 * @param timer callBack
 * @returns 自执行函数
 */

declare global {
  interface Window {
    lastTime: any
  }
}
export const preventCliks = (callBack: Function, timer: number = 500): void => {
  const _lastTime = window.lastTime || 0
  return ((): void => {
    const nowTime = +new Date()
    if (nowTime - _lastTime > timer || !_lastTime) {
      window.lastTime = nowTime
      callBack()
    }
  })()
}

 

posted @ 2022-06-13 19:00  Action_swt  阅读(49)  评论(0编辑  收藏  举报