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

我的最新版chrome48.0.2564.116 m (64-bit) 怎么提示canvas.getContext("2d")出错呢

var canvasWidth=800;
var canvasHeight=canvasWidth;
var isMouseDown=false;
var canvas=document.getElementById("canvas");
var context=canvas.getContext("2d");
canvas.width=canvasWidth;
canvas.height=canvasHeight;
drawGrid();
canvas.onmousedown=function(e){
e.preventDefault();
isMouseDown=true;
//console.log("mouse down");
alert(e.clientX+","+e.clientY);
}
canvas.onmouseup=function(e){
e.preventDefault();
isMouseDown=false;
//console.log("mouse up");
}
canvas.onmouseout=function(e){
e.preventDefault();
isMouseDown=false;
//console.log("mouse out");
}
canvas.onmousemove=function(e){
e.preventDefault();
if(isMouseDown){
//console.log("mouse move");
//draw
}
}
function drawGrid(){
context.save();
context.strokeStyle="red";
context.beginPath();
context.moveTo(3,3);
context.lineTo(canvasWidth-3,3);
context.lineTo(canvasWidth-3,canvasHeight-3);
context.lineTo(3,canvasHeight-3);
context.closePath();
context.lineWidth=6;
context.stroke();
context.beginPath();
context.moveTo(0,0);
context.lineTo(canvasWidth,canvasHeight);
context.moveTo(canvasWidth,0);
context.lineTo(0,canvasHeight);
context.moveTo(canvasWidth/2,0);
context.lineTo(canvasWidth/2,canvasHeight);
context.moveTo(0,canvasHeight/2);
context.lineTo(canvasWidth,canvasHeight/2);
context.lineWidth=1;
context.stroke();
context.restore();
}


正在回答

1 回答

什么错误啊?贴出来

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

开普勒 提问者

Uncaught TypeError: Cannot read property 'getContext' of null 这个IE 火狐都有这个,但是程序能用的。
2016-02-26 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

我的最新版chrome48.0.2564.116 m (64-bit) 怎么提示canvas.getContext("2d")出错呢

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