javascript - My JQuery count down is not working perfectly, -


i want make jquery timer count down. should have days, day, month, hours, seconds. used below code, not working. when browser refreshed, counter restarting. please me correct code.

this jsfiddle https://jsfiddle.net/saifudazzlings/lfldo381/

the js code:

var sec = 60; var min = 100; var hr = 24; var updatetimer = function() {     var timer = localstorage.getitem('timer') || 0;     var timermin = localstorage.getitem('timermin') || 0;     var timerhr = localstorage.getitem('timerhr') || 0;     $("div#timermin").html(timermin);     $("div#timerhr").html(timerhr);      if (timer === 0) {         $("div#timer").html("00");     } else if (timer <= 1) {         timer--;         timermin--;         localstorage.setitem('timermin', timermin);         $("div#timermin").html(timermin);         if (timermin < 1) {             if (timerhr == 0) {                 localstorage.removeitem('timermin', timermin);                 $("div#timermin").html("00");                 localstorage.removeitem('timer', timer);                 $("div#timer").html("00");                 localstorage.removeitem('timerhr', timerhr);                 $("div#timerhr").html("00");             } else {                 timerhr--;                 localstorage.setitem('timerhr', timerhr);                 $("div#timerhr").html(timerhr);                 localstorage.setitem('timermin', min);                 $("div#timermin").html(timermin);              }             //timerhr--;             //localstorage.setitem('timerhr', timerhr);             //$("div#timerhr").html(timerhr);             //localstorage.setitem('timermin', min);             //$("div#timermin").html(timermin);         }          localstorage.setitem('timer', sec);         $("div#timer").html(timer);     } else {         timer--;         localstorage.setitem('timer', timer);         $("div#timer").html(timer);          if (timermin == 0) {             localstorage.removeitem('timer', timer);             $("div#timer").html("00");             $("div#countermessage").html("00");          }     } };  $(function() {     $("#start").click(function() {         localstorage.setitem('timer', sec);      });      $("#start2").click(function() {         localstorage.setitem('timermin', min);         localstorage.setitem('timerhr', hr);     });      setinterval(updatetimer, 1000);      $(window).load(function() {         localstorage.setitem('timer', sec);         localstorage.setitem('timermin', min);         localstorage.setitem('timerhr', hr);     }); }); 


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -