UNPKG

zydx-plus

Version:

Vue.js

25 lines 693 B
export const debounceTimer = 500 // 防抖 export function debounce(fn, delay = debounceTimer) { let timeoutID = null return function () { clearTimeout(timeoutID) let args = arguments let that = this timeoutID = setTimeout(function () { fn.apply(that, args) }, delay) } } export function throttle(fn, limit=debounceTimer) { let inThrottle; return function() { const args = arguments; const context = this; if (!inThrottle) { fn.apply(context, args); inThrottle = true; setTimeout(() => { inThrottle = false; }, limit); } }; }