Skip to content

Instantly share code, notes, and snippets.

@happymishra
Created June 30, 2019 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happymishra/c72365e25ef1f58792ffeebd1e5271c8 to your computer and use it in GitHub Desktop.
Save happymishra/c72365e25ef1f58792ffeebd1e5271c8 to your computer and use it in GitHub Desktop.
<html>
<body>
<button id="click-btn">Click me!</button>
</body>
<script>
var timerId;
var clickBtn = document.getElementById('click-btn');
var clickFunction = function(){
console.log("No matter how many times you click me," +
"I will be called after 1 second you stop clicking me!")
}
var debounceFunction = function(func, delay) {
clearTimeout(timerId)
timerId = setTimeout(function(){
func()
}, 1000)
}
clickBtn.addEventListener('click', function(){
debounceFunction(clickFunction, 200)
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment