A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/apis/canvas/CanvasRenderingContext2D/strokeRect below:

strokeRect · WebPlatform Docs

strokeRect Summary

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

Syntax
var object = object.strokeRect(x, y, w, h);
Parameters x
Data-type
Number

The x-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.

y
Data-type
Number

The y-coordinate, in pixels, of the upper-left corner of the rectangle in relation to the coordinates of the canvas.

w
Data-type
Number

The width, in pixels, of the rectangle in relation to the coordinates of the canvas.

h
Data-type
Number

The height, in pixels, of the rectangle in relation to the coordinates of the canvas.

Return Value

Returns an object of type DOM NodeDOM Node

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Examples

Basic 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 specifications
W3C HTML Canvas 2D Specification
W3C Candidate Recommendation
Attributions

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