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 throttle(fn, wait) { var prev = 0; wait = wait || 1000; return function() { var now = Date.now(); if (now - prev > wait) { fn.apply(this, arguments); prev = now; } } }
应用举例:
window.addEventListener('mousemove', throttle(function() { console.log(Date.now()) }));
The text was updated successfully, but these errors were encountered:
No branches or pull requests
节流是一种常用的性能优化手段,主要原理是:当持续触发事件时,对事件响应进行抽稀,保证一定时间段内只调用一次事件处理函数。
节流函数:
应用举例:
The text was updated successfully, but these errors were encountered: