Last active
January 3, 2024 20:17
-
-
Save nocodesupplyco/6ed6fd25b46682145e622eff4845b30d to your computer and use it in GitHub Desktop.
Show a Preloader Once Per Day
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
// Target the preloader element | |
const preloaderElement = document.getElementById('preloader'); | |
// Set the amount of time to wait in milliseconds | |
// Test by changing to 1 * 60 * 1000 for 1 min | |
const waitTime = 24 * 60 * 60 * 1000; // 24 hours | |
// Check if the local storage item is present and valid | |
if (!localStorage.getItem('preloaderShown') || Date.now() - localStorage.getItem('preloaderShown') > | |
waitTime) { | |
// Show the preloader element | |
preloaderElement.style.display = 'block'; | |
// Store the current timestamp in local storage | |
localStorage.setItem('preloaderShown', Date.now()); | |
} else { | |
// Hide the preloader element | |
preloaderElement.style.display = 'none'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment