1

I am having some issues with JQuery and local storage. I have a div I want to display only once every 4hrs.

Currently, this is my code:

$(function() {

  var now = (new Date()).getTime();
  var lastTime = 0;
  var lastTimeStr = localStorage['lastTime'];
  if (lastTimeStr) lastTime = parseInt(lastTimeStr, 10);
  if (now - lastTime > 24*60*60*1000) {


  //START UP FADEOUT SCREEN
  $('#startup').delay(1500).fadeOut(2000);

  } 
  localStorage['lastTime'] = ""+now;​

});

However, the fadeout no longer works.

Can anyone help me out with this one? Do I need some kind of plugin for localStorage?

Thanks

3
  • That looks fine to me. localStorage is not supported in IE < 8 though. What do you mean by "no longer works"? Commented Jun 12, 2012 at 12:16
  • Well, maybe you run it once and now now - lastTime > 24*60*60*1000 is false for the next 24 hours. You probably should put localStorage['lastTime'] = ""+now;​ inside the if statement. Commented Jun 12, 2012 at 12:17
  • Hi James, prior to this I just had the line: $('#startup').delay(1500).fadeOut(2000); which worked fine. After putting the rest around it, the fadeout animation no longer works - the #startup div stays put. I have tried the same with an alert and its fine. Just doesnt seem to like this animation! Commented Jun 12, 2012 at 12:18

1 Answer 1

1

Felix was right. In my css I had forgotten to apply display:none to the #startup element and so it was covering the screen ('sticking') as the fadeOut function was not running anymore, being set to a 24hr interval.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.