
Untitled
By: a guest on
Jul 20th, 2012 | syntax:
None | size: 1.33 KB | hits: 16 | expires: Never
Run JQuery function just once per visit
$('#startup').delay(1500).fadeOut(2000);
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) {
// do animation
}
localStorage['lastTime'] = ""+now;
/* Here are some utility localStorage functions */
function store_data(data, key) {
if (!window.localStorage || !window.JSON) {
return;
}
key = key || data_key;
localStorage.setItem(key, JSON.stringify(data));
}
function get_data(key) {
if (!window.localStorage || !window.JSON) {
return;
}
key = key || data_key;
var item = localStorage.getItem(key);
if (!item) {
return;
}
return JSON.parse( item );
}
function remove_data(key) {
if (!window.localStorage || !window.JSON) {
return;
}
key = key || data_key;
localStorage.removeItem(key);
}
/* and the check */
var now = (new Date()).getTime(),
then = parseInt(get_data('last_visit'), 10) || 0,
diff = now - then;
if( diff > 24*60*60*1000 ) {
$('#startup').delay(1500).fadeOut(2000);
store_data('last_visit', (new Date()).getTime());
}