We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用场景:对于连续事件响应,只需要执行一次回调
function debounce(func, wait, immediate) { var timeId = null; return function () { clearTimeout(timeId); // 立即执行 if (immediate) { if (!timeId) func.apply(this, arguments); timeId = setTimeout(() => { timeId = null; }, wait); } // 停止后执行 else { timeId = setTimeout(() => { func.apply(this, arguments); }, wait); } } }
使用场景:对于连续事件响应,需要间隔一定时间触发回调来控制函数调用频率
function throttle(func, wait) { var now, previous = 0; return function () { now = +new Date(); if (now - previous > wait) { func.apply(this, arguments); previous = now; } } }
mqyqingfeng/Blog#22 mqyqingfeng/Blog#26
The text was updated successfully, but these errors were encountered:
No branches or pull requests
防抖(Debounce)
节流(Throttle)
Reference
mqyqingfeng/Blog#22
mqyqingfeng/Blog#26
The text was updated successfully, but these errors were encountered: