开发者

Set cookie to only play animation once (jquery)

I have an animation that I am running using jQuery. I am assuming a good way to only play this animation once for the visitor is by setting a cookie. I basically need it to say you've bee开发者_如何学编程n here before so set all the IDs listed to opacity:1 Is there an ultra simple solution to this? Thanks for any help

  $(document).ready(function(){
    $("#featureFade").animate({opacity:1},400,function(){
        $("#image").delay(300).animate({opacity:1},300,function(){
        $("#title").delay(300).animate({opacity:1},300,function(){
        $("#message, #move").delay(200).animate({opacity:1},300,function(){ 
            $("#move").animate({top: '400px',left: '0px'}, 500,function(){
            $("#nav,#contentContainer,#button,#footer,#topLevelNav").delay(1000).animate({opacity:1},700);
                });
                });
                });
            });
    });
});


Using the jQuery Cookie Plugin you can do this simply:

// check for previous visit
if ($.cookie('hasSeenAnimation') == null){
  // ...
  // play animation
  // ...

  // set cookie to stop next visit
  $.cookie('hasSeenAnimation','true');
}


I would do it on the server side - if the cookie is set, just don't output the code for the animation...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜