Last active
March 30, 2020 07:23
-
-
Save tinolove81/03c16e49341ac0db3076a70d36f41bd5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <script> | |
| let isTimerSetup = false; | |
| let timeoutId; | |
| let timeoutInMiliseconds = 600; | |
| let selector = 'popup選擇器'; | |
| function startTimer() { | |
| timeoutId = window.setTimeout(() => { | |
| $(selector).fadeIn(); | |
| }, timeoutInMiliseconds) | |
| } | |
| function resetTimer() { | |
| window.clearTimeout(timeoutId); | |
| startTimer(); | |
| } | |
| $(window).on('keydown scroll', () => { | |
| $(selector).fadeOut(); | |
| if (isTimerSetup == false) { | |
| isTimerSetup = true; | |
| document.addEventListener("mousemove", resetTimer, false); | |
| document.addEventListener("mousedown", resetTimer, false); | |
| document.addEventListener("keypress", resetTimer, false); | |
| document.addEventListener("touchmove", resetTimer, false); | |
| startTimer(); | |
| } else { | |
| resetTimer(); | |
| } | |
| }); | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment