javascript - jQuery Countdown - reset timer -
i'm using jquery countdown plugin , have quick query.
my code looks this:
function docountdown(){ var nextnoon = new date(); if (nextnoon.gethours()>=12){ nextnoon.setdate(nextnoon.getdate()+1); } nextnoon.sethours(11,30,0,0); $('h3 .timer strong').countdown({until: nextnoon, compact: true, description: '', onexpiry: function(){docountdown()}}); } $(window).load(function(){ docountdown(); });
so basically, counts down untill next 11:30am
. need reset counter when reaches 11:30am
, automatically go 23:59:59
on timer.
currently sticks @ 00:00:00
though docountdown
function called onexpiry
(tested console.log
, calls it).
is because javascript bases time off page load , stores it?
the reason because nextnoon
creation miscalculates times between 11:30am , 12:00pm. half hour period, if()
evaluate false, set time 11:30am of current day. we've passed time, since we're between 11:30am , 12noon. countdown go zero.
you need follows:
var todaysnoon = new date(), nextnoon = new date(); todaysnoon.sethours(11,30,0,0); if (todaysnoon <= nextnoon){ nextnoon.setdate(nextnoon.getdate()+1); } nextnoon.sethours(11,30,0,0);
Comments
Post a Comment