我有一个倒计时的小脚本
问题之一是从秒到更好的可读性 0:00
另一个问题是倒计时开始所需的时间
编辑:我想我混了一点 php
window.onload = function() {
canvas = document.getElementById('timer'),
seconds = document.getElementById('counter'),
ctx = canvas.getContext('2d'),
sec = seconds.innerHTML | 0,
countdown = sec;
ctx.lineWidth = 8;
ctx.strokeStyle = "#528f20";
var
startAngle = 0,
time = 0,
mins = 0,
secs = 0,
intv = setInterval(function(){
// Making 180 look like 3:00 is not working
if(sec > 59)
{
mins = Math.floor(sec/60);
secs = Math.floor(sec - mins*60);
if(mins < 10) mins = "0" + mins;
if(secs < 10) secs = "0" + secs;
}
var endAngle = (Math.PI * time * 2 / sec);
ctx.arc(50, 50, 35, startAngle , endAngle, false);
startAngle = endAngle;
ctx.stroke();
seconds.innerHTML = countdown--;
if (++time > sec) { clearInterval(intv); }
}, 1000);