Skip to content

Instantly share code, notes, and snippets.

@onurkerimov
Created November 14, 2018 20:34
Show Gist options
  • Save onurkerimov/04ce5426fe054b5b9222478c78ddbda0 to your computer and use it in GitHub Desktop.
Save onurkerimov/04ce5426fe054b5b9222478c78ddbda0 to your computer and use it in GitHub Desktop.
window.addEventListener("mousemove", function(e) {
debounce(200, fn.bind(this,e))
});
var waitFlag = false
function debounce(time,fn) {
if (!waitFlag) {
fn()
waitFlag = true
setTimeout(function() {
waitFlag = false
}, time)
}
}
function fn(e) {
// Something computationally expensive
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment