【问题标题】:Replace a DIV with another using effect and set cookie用另一个使用效果替换一个DIV并设置cookie
【发布时间】:2010-06-21 22:56:40
【问题描述】:

我有一些复杂的需求,想知道是否有办法通过 jQuery 来完成:

  1. 用户今天第一次访问网页,我们显示 DIV_1。
  2. 30 秒后,我们将 DIV_1 溶解为 DIV_2。
  3. 我们在用户的机器上设置了一个 cookie,当她/他明天返回时过期。
  4. 如果同一用户今天返回,我们只显示 DIV_2。
  5. 明天,我们重复这个过程:用户将看到 DIV_1,然后它溶解为 DIV_2。

你是如何通过 jQuery 来实现的?谢谢。

【问题讨论】:

    标签: jquery cookies html


    【解决方案1】:

    http://plugins.jquery.com/project/Cookie

    $(function(){
         if(!$.cookie('repeatVisitor')){
             $.cookie("repeatVisitor", "true", { expires: 1 }); //expires in 1 day
             setTimeout('showDivTwo();', 30000);    
         }
    })
    
    function showDivTwo(){
        $('#divOne').fadeOut();
        $('#divTwo').fadeIn();
    }
    

    【讨论】:

    • 谢谢,德米特里。哇!你让它看起来很容易:)
    • 追问:如果DIV_2要替换DIV_1,你是否将它的STYLE设置为display:none?它现在不适合我。
    • 对 setTimeout 的正确调用是这样的:setTimeout('showDivTwo()', 30000);
    • 抱歉,我将在 setTimeout 中进行编辑 :) fadeOut 将负责设置 display none。
    猜你喜欢
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 2013-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 2014-02-12
    相关资源
    最近更新 更多