-1
// Intro animation
setTimeout(function(){ 
    $('.intro').addClass("intro_hide")
  }, 3000);

I want to show this div (intro) only the first time you enter the website. When you go to another page and go back to the homepage this shouldn't show. Only when you do a hard refresh or come back to the website after a long time.

  • Sounds like you're potentially wanting to use some sort of cookie/session storage to keep track of when the intro should not show. – Taplar Oct 10 '19 at 14:30
  • 1
    Possible duplicate of [Run jQuery code only the first time a user visits the website](https://stackoverflow.com/questions/35397732/run-jquery-code-only-the-first-time-a-user-visits-the-website) – ReSedano Oct 10 '19 at 14:31

1 Answers1

0

You should store somewhere that user has played the intro, this storage should be more persistent that just variable, so you should use cookies, localStorage or sessionStorage. SessionStorage fits your requirements, because it resets its state when the window or tab is closed.

// Hide intro if has been played before
if (sessionStorage.getItem("introPlayed")) {
  $('.intro').hide()
} else {
  // Intro animation
  setTimeout(function() { 
    $('.intro').addClass("intro_hide");
    // Store information that user has played intro
    // In sessionStorage data is persisted only until the window or tab is closed
    sessionStorage.setItem("introPlayed", true);
  }, 3000);
}