Created
April 16, 2017 19:11
-
-
Save thomhines/908dc2e88bce84c5f06c9e9325b84f12 to your computer and use it in GitHub Desktop.
jQuery Debounce
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
| var validation_debounce_timeout; | |
| $.fn.debounce = function(callback, delay) { | |
| $this = $(this); | |
| clearTimeout(validation_debounce_timeout); | |
| validation_debounce_timeout = setTimeout(function() { | |
| callback(); | |
| }, delay); | |
| } | |
| // You must refer to "this" input as $this in callback function, like so: | |
| $('input').debounce(function() { | |
| console.log($this.val()); | |
| }, 700); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment