Created
April 2, 2017 12:29
-
-
Save severuykhin/3c22576f08d65fafbf9f64a1927cb4ef to your computer and use it in GitHub Desktop.
Converts several function calls within a certain time into one call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var debounce = function (f, ms){ | |
var state = null; | |
var COOLDOWN = 1; | |
return function(){ | |
if(state) return; | |
f.apply(this. arguments); | |
state = COOLDOWN; | |
setTimeout(function(){state = null}, ms); | |
} | |
} | |
let width = 1; | |
var action = function(){ | |
document.querySelector('#text').style.transform = `scale(1.${width})`; | |
width++; | |
} | |
document.querySelector('button').onclick = debounce(action, 5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment