Run jQuery only once when the site is loaded

Asked

Viewed 398 times

0

I am having a problem, I have the script below that every time the user uses the browser to go back to main page this animation script runs.

I wonder if there is something I can do for it to run only on the first user access, even without refresh.

$(document).ready(function() {
  /*ANIMAÇOES*/
  //$(".bolhasanimadas").addClass('animated slideInUp');
  $(".bolhasanimadas").addClass('animated slideInUp');
  $(".animacaoBolhas").delay(4000).slideToggle(50);
  $(".LogoAnimado").delay(800).fadeToggle(1);
  //$(".LogoAnimado").toggle( 6500 ).delay( 6500 );

  /*BARRA DE ROLAGEM*/
  setTimeout(function() {
    //$('body').css('overflow-y', 'scroll');
    $('body').addClass('barraOn');
  }, 4000);

});

Explaining better: Actually this jquery is an animation. And I would need a script to run this animation only when the user enters the site once. After it has been browsing and by chance give refresh or go back in the browser to Home and animation will not run again. This idea of leaving animation on an index alone doesn’t help me.

  • Dude, you’ll have to use a server side language (php, Asp).... If it’s php, create a Session the first time it enters

  • Guilherme, only with this jQuery script can not reproduce the problem, could complement it ?

  • Actually this jquery is an animation. And I would need a script to run this animation only when the user enters the site once. After it has been browsing and by chance give refresh or go back in the browser to Home and animation will not run again. This idea of leaving the animation on an index alone does not help me.

1 answer

0

Document.ready runs every time the page is created. html does not recognize a postback, that is, when it comes back through the browser everything in Document.ready will run again.

From the descriptions, it looks like an animation on the front page. I don’t know if it is, but if it is, you could use a main page that will run once. A default.html/index.html page, which after showing the animations redirects to home.html for example.

By doing this you will be separating the incoming animation of your website from your home page. So every time the user goes back to home.html page he won’t see the animation again.

You will only see the animation the first time you enter the site.

I don’t know if it’s too clear.

Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.