Set cookie to only play animation once (jquery)

ⅰ亾dé卋堺 提交于 2020-01-14 02:52:10

问题


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 been 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);
                });
                });
                });
            });
    });
});

回答1:


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');
}



回答2:


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



来源:https://stackoverflow.com/questions/6239020/set-cookie-to-only-play-animation-once-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!