SHARE
TWEET

Untitled




Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- // 防抖
- let timeoutKey;
- function antiShake (cb) {
- window.clearTimeout(timeoutKey);
- timeoutKey = setTimeout(cb, 500);
- }
- function getDebounceFunc (cb, interval) {
- let timer;
- return () => {
- clearTimeout(timer);
- timer = setTimeout(cb, interval)
- }
- }
- // 节流
- function throttle(fn, gapTime) {
- let _lastTime = null;
- return function () {
- let _nowTime = + new Date()
- if (_nowTime - _lastTime > gapTime || !_lastTime) {
- fn();
- _lastTime = _nowTime
- }
- }
- }
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.