Created
June 24, 2018 19:08
-
-
Save cameroncowden/3cd1f3afa01d1e7bf4a9fdd9deb1b46f to your computer and use it in GitHub Desktop.
Simple debouncer
This file contains 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
//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