html5 canvas怎么画两个矩形

如题所述

var canvas=document.getElementById('canvas');
var ctx =getContext('2d');
ctx.beginPath();
ctx.lineWidth=1;
ctx.strokeStyle="#000";
ctx.rect(0,0,10,20);
ctx.stroke();
ctx.closePath();
//用closepath结束绘画,否则可能出现黏连;
ctx.beginPath();
ctx.lineWidth=1;
ctx.strokeStyle="#f00";
ctx.rect(50,0,10,20);
ctx.stroke();
ctx.closePath();
温馨提示:答案为网友推荐,仅供参考
第1个回答  2017-03-24
用moveTo(x,y)和lineTo(x1,y1)就可以。

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网