Simple piece of jQuery that adds the class .typing to the <html> tag while the user is currently typing. I’ve tried several different things that all haven’t worked, not sure how else to do this.
$('html').keypress(function(){
$(this).addClass('typing');
if ( /* No key is pressed again in the next 0.5 seconds */ ) {
$('.typing').removeClass('typing');
}
});
Create a function which executes certain code after 0.5 seconds, using
setTimeout(in conjunction withclearTimeout, to prevent multiple timeouts from be active at a time).