求大神指教,為什么我這個(gè)定時(shí)器不起作用呢?
var WINDOW_WIDTH=400;//畫布長度
var WINDOW_HEIGHT=300;//畫布高度
var RADIUS=2;//每個(gè)數(shù)字中小圓點(diǎn)的半徑
var MARGIN_LEFT=20;//第一個(gè)數(shù)字離畫布左邊的距離
var MARGIN_TOP=30;//第一個(gè)數(shù)字離畫布上邊的距離
//截止的日期
const endTime=new Date(2015,11,5,18,47,52);
var curShowTimeSeconds=0;
window.onload=function(){
? ?var canvas=document.getElementById('canvas');
? ?//獲取畫布環(huán)境
? ?var context=canvas.getContext('2d');
? ?canvas.width=WINDOW_WIDTH;
? ?canvas.height=WINDOW_HEIGHT;
? ?curShowTimeSeconds=getCurrentShowTimeSeconds();
? ?//定時(shí)器每隔50毫秒執(zhí)行一次程序
? ?setInterval(function(){
? ? ? ?render(context);
? ? ? ?update();
? ?},50);
}
//獲取截止日期到現(xiàn)在日期的差值
function getCurrentShowTimeSeconds(){
? ?var curTime=new Date();
? ?var ret=endTime.getTime()-curTime.getTime();//毫秒
? ?ret=Math.round(ret/1000);//轉(zhuǎn)換成秒
? ?return ret>=0?ret:0;//若差值大于0則返回,若小于0,則返回0
}
function update(){
? var ?nextShowTimeSeconds=getCurrentShowTimeSeconds();
? ?var nextHours=parseInt(nextShowTimeSeconds/3600);
? ?var nextMinutes=parseInt((nextShowTimeSeconds-nextHours*3600)/60);
? ?var nextSeconds=nextShowTimeSeconds%60;
? ?//截止的小時(shí)
? ?var curHour=parseInt(curShowTimeSeconds/3600);
? ?//截止的分鐘
? ?var curMinutes=parseInt((curShowTimeSeconds-hour*3600)/60);
? ?//截止的分鐘
? ?var curSeconds=curShowTimeSeconds%60;
? ?if(nextSeconds!=curSeconds){
? ? ? ?curShowTimeSeconds=nextShowTimeSeconds;
? ?}
}
//畫出此刻離截止日期的時(shí)間
function render(cxt){
? ?cxt.clearRect(0,0,WINDOW_WIDTH,WINDOW_HEIGHT);
? ?//截止的小時(shí)
? ?var hour=parseInt(curShowTimeSeconds/3600);
? ?//截止的分鐘
? ?var minutes=parseInt((curShowTimeSeconds-hour*3600)/60);
? ?//截止的分鐘
? ?var seconds=curShowTimeSeconds%60;
? ?renderDigit(MARGIN_LEFT,MARGIN_TOP,parseInt(hour/10),cxt);
? ?renderDigit(MARGIN_LEFT+15*(RADIUS+1),MARGIN_TOP,parseInt(hour%10),cxt);
? ?renderDigit(MARGIN_LEFT+30*(RADIUS+1),MARGIN_TOP,10,cxt);
? ?renderDigit(MARGIN_LEFT+39*(RADIUS+1),MARGIN_TOP,parseInt(minutes/10),cxt);
? ?renderDigit(MARGIN_LEFT+54*(RADIUS+1),MARGIN_TOP,parseInt(minutes%10),cxt);
? ?renderDigit(MARGIN_LEFT+69*(RADIUS+1),MARGIN_TOP,10,cxt);
? ?renderDigit(MARGIN_LEFT+78*(RADIUS+1),MARGIN_TOP,parseInt(seconds/10),cxt);
? ?renderDigit(MARGIN_LEFT+93*(RADIUS+1),MARGIN_TOP,parseInt(seconds%10),cxt);
}
//畫出每個(gè)數(shù)字
function renderDigit(x,y,num,cxt){
? ?//圓點(diǎn)的顏色
? ?cxt.fillStyle="rgb(0,102,153)";
? ?//對lend1進(jìn)行遍歷,i是每個(gè)數(shù)字的行數(shù),j是沒個(gè)數(shù)字的列數(shù)
? ?for(var i=0;i<lend1[num].length;i++){
? ? ? ?for(var j=0;j<lend1[num][i].length;j++){
? ? ? ? ?if(lend1[num][i][j]==1){
? ? ? ? ? ? ?cxt.beginPath();
? ? ? ? ? ? ?cxt.arc(x+j*2*(RADIUS+1)+(RADIUS+1),y+i*2*(RADIUS+1)+(RADIUS+1),RADIUS,0,2*Math.PI);
? ? ? ? ? ? ?cxt.closePath();
? ? ? ? ? ? ?cxt.fill();
? ? ? ? ?}
? ? ? ?}
? ?}
}
2015-12-04
lend1 你這個(gè)數(shù)組在哪里?