How to convert JavaScript functions to jQuery for a countdown timer on load of a page -
i have following code countdown timer. need convert javascript portion jquery. countdown timer starts on page load. how can that, have load difftime function on load of page. please me. in advance.
edit: got jquery call can not access ** function tick() ** ** function createtimer() ** . there library ** settimeout() ** in jquery? know far, native js.
<html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript"> var timer; var totalseconds; function createtimer(timerid, time) { timer = document.getelementbyid(timerid); totalseconds = time; //updatetimer() window.settimeout("tick()", 1000); } function tick() { if (totalseconds <= 0) { //alert("time's up!") document.getelementbyid("timemsg").innerhtml = "market closed!! "; return; } totalseconds -= 1; updatetimer() window.settimeout("tick()", 1000); } function updatetimer() { var seconds = totalseconds; var days = math.floor(seconds / 86400); seconds -= days * 86400; var hours = math.floor(seconds / 3600); seconds -= hours * (3600); var minutes = math.floor(seconds / 60); seconds -= minutes * (60); var timestr = ((days > 0) ? days + " days " : "") + leadingzero(hours) + ":" + leadingzero(minutes) + ":" + leadingzero(seconds) timer.innerhtml = timestr; } function leadingzero(time) { return (time < 10) ? "0" + time : + time; } function difftime(){ var starttime = 10*60 + 30; //starting time in minute var lasttime = 16*60 + 30; //ending time in minutes var thistime = new date(); // var currentyear = thistime.getfullyear(); var currentmonth = thistime.getmonth(); var currentday = thistime.getutcdate(); var currenthour = thistime.gethours(); var currentminute = thistime.getminutes(); var currenttime = currenthour*60 + currentminute; //current time in minute if(currenttime >= starttime && currenttime < lasttime){ var endtime = new date(currentyear,currentmonth,currentday,16,30); // 4:30pm var diff = endtime.gettime() - thistime.gettime(); // var remaintime = diff / (1000); // positive number of days remaintime = math.ceil(remaintime); createtimer("timer", remaintime); }else{ document.getelementbyid("timemsg").innerhtml = "market closed!! "; document.getelementbyid("timer").innerhtml = "00:00:00"; } } window.onload = difftime; </script> </head> <body> <div><span id="timemsg">elapsed time remain: </span><b><span id='timer'></span></b></div> </body>
call function in document.ready()
$( document ).ready( function () { difftime(); });
Comments
Post a Comment