为什么对矩形设置了描边不起作用?
来源:3-9 填充与描边
qq_鸭绿桥第一帅哥_0
2019-04-19 16:44:10
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>canvas</title>
<style>
canvas {
border: 1px solid red;
}
</style>
</head>
<body>
<canvas id="canvas" width="800" height="800">
您的浏览器不支持canvas
</canvas>
<script>
//在此处写出代码
var canvas=document.getElementById('canvas');
var txt=canvas.getContext('2d');
txt.moveTo(0,0);
txt.lineTo(100,100);
txt.lineTo(100,170);
txt.lineWidth=10;
txt.closePath();
txt.strokeStyle="red";
txt.stroke();
txt.fillStyle='rgba(0,255,0,.5)';
txt.fill();
txt.beginPath();
txt.strokeRect(100,200,100,100);
txt.strokeStyle="green";
txt.lineWidth=5;
txt.fillStyle='red';
txt.fillRect(100,200,100,100);
</script>
</body>
</html>1回答
绘制矩形x、y坐标 width height的这个方法要放在前面

效果图:

希望可以帮到你!
相似问题