Created
June 30, 2019 18:48
-
-
Save happymishra/c72365e25ef1f58792ffeebd1e5271c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<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