views:

17

answers:

1

Hi. I've got some complicated requirements and wondered if there's a way to accomplish this via jQuery:

  1. User comes to a web page for the first time today and we show DIV_1.
  2. After 30 seconds, we dissolve DIV_1 to DIV_2.
  3. We set a cookie on the user's machine that expires when s/he returns tomorrow.
  4. If the same user returns today, we only show DIV_2.
  5. Tomorrow, we repeat the process: The user will see DIV_1 and then it dissolves to DIV_2.

How do you accomplish this via jQuery? Thank you.

+1  A: 

with 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();
}
Dmitri Farkov
Thanks, Dmitri. Wow! You make it looks so easy :)
Alex
A followup: If DIV_2 is to replace DIV_1, do you set its STYLE to display:none? It's not working for me right now.
Alex
The correct call to the setTimeout is this: setTimeout('showDivTwo()', 30000);
Alex
Sorry, I will edit in the setTimeout :) fadeOut will take care of setting display none.
Dmitri Farkov