Skip to content

Instantly share code, notes, and snippets.

@banderson623
Created August 9, 2014 15:39
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 banderson623/be6a15bc9147ebc520a5 to your computer and use it in GitHub Desktop.
Save banderson623/be6a15bc9147ebc520a5 to your computer and use it in GitHub Desktop.
var throttle = function(timeOutInMs,funct){
var timer = 0;
return function(){
var context = this;
// no op timer running
if (timer !== 0){return;}
var doIt = function(){
funct.apply(context);
timer = 0;
};
timer = setTimeout(doIt, timeOutInMs);
};
};
var throttledValue = throttle(250,function(){
console.log("value " + $(this).val());
});
$("#average-temp-range").on("change", throttledValue);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment