SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 防抖
  2. let timeoutKey;
  3. function antiShake (cb) {
  4.     window.clearTimeout(timeoutKey);
  5.     timeoutKey = setTimeout(cb, 500);
  6. }
  7.  
  8. function getDebounceFunc (cb, interval) {
  9.     let timer;
  10.     return () => {
  11.         clearTimeout(timer);
  12.         timer = setTimeout(cb, interval)
  13.     }
  14. }
  15.  
  16. // 节流
  17. function throttle(fn, gapTime) {
  18.   let _lastTime = null;
  19.  
  20.   return function () {
  21.     let _nowTime = + new Date()
  22.     if (_nowTime - _lastTime > gapTime || !_lastTime) {
  23.       fn();
  24.       _lastTime = _nowTime
  25.     }
  26.   }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top