Takes the result of tracing the path, using the CanvasRenderingContext2D object’s line styles, and fills it with the strokeStyle.
Method of apis/canvas/CanvasRenderingContext2Dapis/canvas/CanvasRenderingContext2D
Syntaxvar object = object.strokeRect(x, y, w, h);
Parameters x
The x-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.
yThe y-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.
wThe width, in pixels, of the rectangle in relation to the coordinates of the canvas.
hThe height, in pixels, of the rectangle in relation to the coordinates of the canvas.
Return ValueReturns an object of type DOM NodeDOM Node
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
ExamplesBasic example drawing a 100 x 100 px rect with a red outline
ctx.strokeStyle = 'red';
ctx.strokeRect(10,10,100,100);
Draws a rect with a white outline onto a black canvas
<!DOCTYPE html>
<html>
<head>
<title>Canvas Example</title>
<script>
function draw() {
var canvas = document.getElementById("MyCanvas");
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.strokeStyle = 'white';
ctx.strokeRect(10,10,100,100);
}
}
</script>
</head>
<body onload="draw();">
<canvas id="MyCanvas" width="600" height="500">This browser or document mode doesn't support canvas</canvas>
</body>
</html>
Notes
The strokeRect method creates a path that requires the use of the stroke method to render the rectangle. The outline uses the current strokeStyle, lineWidth, lineJoin, and, when appropriate, miterLimit properties. If the w or h parameter is zero, a line is drawn. If the w and h parameters are zero, the rectangle is not drawn.
Related specificationsMicrosoft Developer Network: Windows Internet Explorer API reference Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4