请问这里哪里出问题了
照着视频完成的,但最后怎么刷新都是显示这个,请问是哪里出问题了
html文件:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Countdown</title> <link rel="stylesheet" href="./style/style.css"> </head> <body> <canvas id="countdown"> 当前浏览器不支持Canvas,请更换浏览器后再试 </canvas> <script type="text/javascript" src="Countdown-digit.js"></script> <script type="text/javascript" src="Countdown.js"></script> </body> </html>
Countdown-digit.js文件:
// 存放模型 digit = [ [ [0, 0, 1, 1, 1, 0, 0], [0, 1, 1, 0, 1, 1, 0], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [0, 1, 1, 0, 1, 1, 0], [0, 0, 1, 1, 1, 0, 0] ], //0 [ [0, 0, 0, 1, 1, 0, 0], [0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1] ], //1 [ [0, 1, 1, 1, 1, 1, 0], [1, 1, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 0, 0, 0], [0, 1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 1, 1], [1, 1, 1, 1, 1, 1, 1] ], //2 [ [1, 1, 1, 1, 1, 1, 1], [0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 0], [0, 0, 0, 0, 1, 1, 0], [0, 0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0, 0, 0, 1, 1], [0, 1, 1, 1, 1, 1, 0], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [0, 1, 1, 1, 1, 1, 0] ], //8 [ [0, 1, 1, 1, 1, 1, 0], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [1, 1, 0, 0, 0, 1, 1], [0, 1, 1, 1, 0, 1, 1], [0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 0, 1, 1], [0, 0, 0, 0, 1, 1, 0], [0, 0, 0, 1, 1, 0, 0], [0, 1, 1, 0, 0, 0, 0] ], //9 [ [0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 1, 1, 0], [0, 1, 1, 0], [0, 0, 0, 0], [0, 0, 0, 0] ] //: ];
Countdown.js文件
var radius = 8; var margin_top = 60; var margin_left = 30; const endTime = new Date(2019, 7, 14, 22, 04, 52); var currentShowTimeSeconds = 0; window.onload = function() { var countdown = document.getElementById("countdown"); countdown.width = 1000; countdown.height = 700; if (countdown.getContext("2d")) { var context = countdown.getContext("2d"); } else { alert("当前浏览器不支持Canvas,请更换浏览器后再试"); } currentShowTimeSeconds = getCurrentShowTimeSeconds(); render(context); } function getCurrentShowTimeSeconds() { var currentTime = new Date(); var ret = endTime.getTime() - currentTime.getTime(); ret = Math.round(ret / 1000); return ret >= 0 ? ret : 0; } function render(context) { var hours = parseInt(currentShowTimeSeconds / 3600); var minutes = parseInt((currentShowTimeSeconds - hours * 3600) / 60); var seconds = currentShowTimeSeconds % 60; renderDigit(margin_left, margin_top, parseInt(hours / 10), context); renderDigit(margin_left + 15 * (radius + 1), margin_top, parseInt(hours % 10), context); renderDigit(margin_left + 30 * (radius + 1), margin_top, 10, context); renderDigit(margin_left + 39 * (radius + 1), margin_top, parseInt(minutes / 10), context); renderDigit(margin_left + 54 * (radius + 1), margin_top, parseInt(minutes % 10), context); renderDigit(margin_left + 69 * (radius + 1), margin_top, 10, context); renderDigit(margin_left + 78 * (radius + 1), margin_top, parseInt(seconds / 10), context); renderDigit(margin_left + 93 * (radius + 1), margin_top, parseInt(seconds % 10), context); } function renderDigit(x, y, num, context) { context.fillStyle = "rgb(0, 102, 153)"; for (var i = 0; i < digit[num].length; i++) { for (var j = 0; j < digit[num][i].length; j++) { if (digit[num][i][j] == 1) { context.beginPath(); // 第(i,j)个圆的圆心位置 context.arc(x + j * 2 * (radius + 1) + (radius + 1), y + i * 2 * (radius + 1) + (radius + 1), radius, 0, 2 * Math.PI); context.closePath(); context.fill(); } } } }