HTML canvas strokeRect () method
Examples
Draw a rectangle 150 * 100 pixels:
JavaScript:
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
ctx.strokeRect(20,20,150,100);
var ctx=c.getContext("2d");
ctx.strokeRect(20,20,150,100);
try it"
Browser Support
Internet Explorer 9, Firefox, Opera, Chrome and Safari support strokeRect () method.
Note: 8 and earlier versions of Internet Explorer do not support the <canvas> element.
Definition and Usage
strokeRect () method to draw a rectangle (no fill). The default color is black strokes.
Tip: Use strokeStyle property to set the stroke color, gradient, or pattern.
JavaScript syntax: | context .strokeRect (x, y, width, height); |
---|
Parameter Value
参数 | 描述 |
---|---|
x | 矩形左上角的 x 坐标。 |
y | 矩形左上角的 y 坐标。 |
width | 矩形的宽度,以像素计。 |
height | 矩形的高度,以像素计。 |