简体   繁体   中英

Loading welcome animation only once jquery/php

In my site i have a welcome animation (created with jquery) which runs when any one opens my website ( www.mysite.com ). Then the same user going to anther page in my site for example www.mysite.com/about then click back to home ( www.mysite.com ) the animation again shows up. How can i restrict this ?

Share some logic like putting a session or settimeout or something like that.

You can set cookie either on server side or either client side And check whether the cookie is set or not if cookie is set then dont show welcome box otherwise show the welcome box...

In php you can set session cookie using setcookie function please see below link:-

http://php.net/manual/en/function.setcookie.php

See the following link for information on how to setup cookies using JQuery: How do I set/unset cookie with jQuery?

Everytime you load the homepage, you can check if the cookie is set using an if-statement. If the cookie is not set, run the animation.

Within the animation-script; make sure that you set the cookie so that the script won't run again while the cookie is active.

This is how you could do it using jquery cookie plugin :

http://jsfiddle.net/lollero/2nYBV/ ( or http://jsfiddle.net/lollero/2nYBV/show/ )

You might want to change the way cookie expires. That info can be found in the plugin page. The way I did it, it expires after every browser session.

jQuery:

You could just as easily reverse this to hide, if the cookie is set. 1. Set cookie 2. if statement to trigger hide, if cookie is set.

// If "welcome" cookie is not set...
if ( $.cookie('welcome') === null ) {
    // Show welcome text.
    $('#welcome').show();
    // Set the "welcome" cookie, so that the 
    // welcome text will not be shown after this.
    $.cookie('welcome', true );
}
​

CSS:

#welcome { 
    display: none; 
}​

HTML:

<div id="welcome">Welcome</div>​

放置带有标志的计时器,然后重定向到您网站的主页。

 setTimeout(function() {window.location.href = "/NewPage.php";}, 2000);

You can use a session to handle this. An example:

<?php
$_SESSION['new'] = true;
?>

首次访问主页时-在cookie中定义一个标志,然后在每次访问页面时检查该标志

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM