Skip to content

Instantly share code, notes, and snippets.

@cameroncowden
Created June 24, 2018 19:08
Show Gist options
  • Save cameroncowden/3cd1f3afa01d1e7bf4a9fdd9deb1b46f to your computer and use it in GitHub Desktop.
Save cameroncowden/3cd1f3afa01d1e7bf4a9fdd9deb1b46f to your computer and use it in GitHub Desktop.
Simple debouncer
//after a click, wait 2 seconds before showing the cta bar. if they click again, reset the timer.
// ie after 2 seconds of inactivity, show the cta
var duration;
$('.ctrl-wrapper').on("click", function(){
$('#global_cat').addClass('is-hidden'); //add class to hide cta
autoShowCta();
});
function autoShowCta() {
clearTimeout(duration);
duration = setTimeout(showAgain, 2000);
}
function showAgain(){
console.log('--showing cta--');
$('#global_cat').removeClass('is-hidden');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment