Skip to content

Instantly share code, notes, and snippets.

@zzuhan
Created October 21, 2013 15:14
Show Gist options
  • Save zzuhan/7085542 to your computer and use it in GitHub Desktop.
Save zzuhan/7085542 to your computer and use it in GitHub Desktop.
code_structure single var
$('#timer').focus(function(){
// turn on timer
startTimer();
}).blur(function(){
// turn off timer
endTimer();
});
var lastValue = "",
$timer = $('#timer'),
timerCheckCount = 0,
checkInputChange = function(){
timerCheckCount++;
if(lastValue !== $timer.val()) {
$timer.next().stop(true, true).fadeIn(0).html('[timer detected changed'+
timerCheckCount + 'times!]' + $timer.val()).fadeOut(2000);
lastValue = $timer.val();
}
},
timer = null,
startTimer = function(){
timer = startTimer(checkInputChange, 200);
},
endTimer = function(){
clearInterval(timer);
timerCheckCount = 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment