Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 1.33 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Run JQuery function just once per visit
  2. $('#startup').delay(1500).fadeOut(2000);
  3.        
  4. var now = (new Date()).getTime();
  5. var lastTime = 0;
  6. var lastTimeStr = localStorage['lastTime'];
  7. if (lastTimeStr) lastTime = parseInt(lastTimeStr, 10);
  8. if (now - lastTime > 24*60*60*1000) {
  9.      // do animation
  10. }
  11. localStorage['lastTime'] = ""+now;
  12.        
  13. /* Here are some utility localStorage functions */
  14.     function store_data(data, key) {
  15.         if (!window.localStorage || !window.JSON) {
  16.             return;
  17.         }
  18.         key = key || data_key;
  19.         localStorage.setItem(key, JSON.stringify(data));
  20.     }
  21.  
  22.     function get_data(key) {
  23.         if (!window.localStorage || !window.JSON) {
  24.             return;
  25.         }
  26.         key = key || data_key;
  27.         var item = localStorage.getItem(key);
  28.  
  29.         if (!item) {
  30.             return;
  31.         }
  32.  
  33.         return JSON.parse( item );
  34.     }
  35.  
  36.     function remove_data(key) {
  37.         if (!window.localStorage || !window.JSON) {
  38.             return;
  39.         }
  40.         key = key || data_key;
  41.         localStorage.removeItem(key);
  42.     }
  43.    /* and the check */
  44.    var now = (new Date()).getTime(),
  45.        then = parseInt(get_data('last_visit'), 10) || 0,
  46.        diff = now - then;
  47.     if( diff > 24*60*60*1000 ) {
  48.        $('#startup').delay(1500).fadeOut(2000);
  49.        store_data('last_visit', (new Date()).getTime());
  50.     }