为了账号安全,请及时绑定邮箱和手机立即绑定

为啥写出来数字只有上半部分,没有下半部分?哪位大神帮帮忙

<!DOCTYPE html><html lang='zh-cn'>    <head>        <title></title>        <meta charset="utf-8">    </head>    <body>        <canvas id="canvas" style="display: block;margin: 50px auto;"></canvas>        <script src="digit.js"></script>        <script type="text/javascript">            var WINDOW_WIDTH=1024;            var WINDOW_HEIGHT=768;            var RADIUS=8;            var MARGIN_TOP=60;            var MARGIN_LEFT=30;            window.onload=function(){                var canvas=document.getElementById('canvas');                var context=canvas.getContext('2d');                                canvas.width=WINDOW_WIDTH;                canvas.heihgt=WINDOW_HEIGHT;                                render(context);            }            function render(cxt){                var hours=12;                var minutes=34;                var seconds=56;                renderDigit(MARGIN_LEFT,MARGIN_TOP,parseInt(hours/10),cxt);                renderDigit(MARGIN_LEFT+15*(RADIUS+1),MARGIN_TOP,parseInt(hours%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);            }            function renderDigit(x,y,num,cxt){                cxt.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){                            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();                        }                       }                }            }        </script>    </body></html>

http://img1.sycdn.imooc.com//600f7a1f0001e49a15750512.jpg

正在回答

2 回答

canvas.heihgt=WINDOW_HEIGHT;      前面的height写错了 改成canvas.height=WINDOW_HEIGHT; 

0 回复 有任何疑惑可以回复我~

浏览器运行的时候把高度修改了(浏览器自作主张),强制指定一下canvas的高度就可以显示了

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

为啥写出来数字只有上半部分,没有下半部分?哪位大神帮帮忙

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信