JQuery: fading in a web page only once

I have a simple script to disappear on the website homepage, for example:

jQuery(document).ready(function(){    
  $('body.home').hide();
  $('body.home').fadeIn('slow');
});

However, I would like the script to work only once as soon as the site loads initially. On subsequent clicks, when, say, the user goes to the secondary page and then returns to the home page, I don’t want the page to fade again, it should just be a downloadable page without fading.

Is there a way to do this with only jQuery code, maybe somehow to execute the function only once, and then stop it from executing? Any tips and code snippets would be greatly appreciated!

+3
source share
3 answers

" " AJAX, javascript, , .

( ), JavaScript. cookie, local storage script .

0

cookie.

$(function () {
  if ($.cookie("loaded") != "true") {
      $('body.home').hide().fadeIn('slow');
      $.cookie("loaded", "true");
  }
});
+8

you can dive into the php world and check if the session exists if there is nobody there .. fade out. I could send a code if you want to go down this route

Quick read if your new for php and sessions: http://www.tizag.com/phpT/phpsessions.php

+1
source

Source: https://habr.com/ru/post/1758713/


All Articles