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
- }
- }
- }
Add Comment
Please, Sign In to add comment