点评:在canvas中当在canvas上写width和height时为canvas的实际画板大小,默认情况下width为300px,height为150px,接下来详细介绍,感兴趣的朋友可以参考下
在canvas中当在canvas上写width和height时为canvas的实际画板大小,默认情况下width为300px,height为150px。复制代码
代码如下:
<!DOCTYPE html>
<head>
<meta charset=utf-8 />
<title>canvas</title>
<script type='text/javascript'>
window.onload = function(){
getCanvas();
};
//canvase绘图
function getCanvas(){
//获得canvas元素及其绘图上下文
var canvas = document.getElementById('canvasId');
var context = canvas.getContext('2d');
//用绝对路标来创建一条路径
context.beginPath();
context.moveTo(0,200);
context.lineTo(200,0);
//将这条先绘制到canvas上
context.stroke();
}
</script>
</head>
<body>
<canvas ></canvas>
</body>
</html>
新闻热点
疑难解答