var TO;
var starttime = 100;
+ var timer = 0;
function start() {
starttime = document.getElementById('set').value;
+ document.getElementById('tim').className='';
if(!isInt(starttime)) {
document.getElementById('tim').innerHTML = 'X';
return;
}
- document.getElementById('tim').innerHTML = starttime;
+ starttime = starttime*60;
+ timer = starttime+10;
clearInterval(TO);
- TO = setInterval('update()',60000);
+ TO = setInterval('update()',10000);
+ update();
}
function update() {
- x = document.getElementById('tim').innerHTML;
- x = x-1;
- document.getElementById('tim').innerHTML = x;
+ timer = timer-10;
+ document.getElementById('tim').innerHTML = Math.ceil(timer/60);
+ document.getElementById('timsmall').innerHTML = Math.floor(timer/60)+':'+((timer%60)?(timer%60):'00');
- if(x<= 0) document.getElementById('tim').className='shutup';
- else if(x <= starttime/10) document.getElementById('tim').className='hurry';
- else if(x<=starttime/3) document.getElementById('tim').className='warn';
+ if(timer<= 0) document.getElementById('tim').className='shutup';
+ else if(timer <= starttime/10) document.getElementById('tim').className='hurry';
+ else if(timer<=starttime/3) document.getElementById('tim').className='warn';
else document.getElementById('tim').className='';
//if (x==0) {clearInterval(TO);}
}
<body>
<div id="tim">
00</div>
+<div id="timsmall"></div>
<div id="setting">
<input type="text" id="set" onChange="start()" value="10"/>
<input type="button" value="start" onClick="start()"/>