A RetroSearch Logo

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

Search Query:

Showing content from https://webplatform.github.io/docs/canvas/methods/getContext below:

getContext ยท WebPlatform Docs

getContext

Method of dom/HTMLCanvasElementdom/HTMLCanvasElement

Syntax
var object = object.getContext();
Parameters contextId
Data-type
any

The identifier (ID) of the type of canvas to create.

Return Value

Returns an object of type DOM NodeDOM Node

ICanvasRenderingContext2D

The context object.

Examples

The following code example uses getContext to get a context to use to show a filled rectangle and filled text.

<!DOCTYPE html>
<head>
  <script type="text/javascript">
function draw()
{
  var canvas = document.getElementById("MyCanvas");
  if (canvas.getContext)
    {
    var ctx = canvas.getContext("2d");
    ctx.font = "italic 36px/2 Unknown Font, sans-serif";
    ctx.fillStyle = "blue";
    ctx.fillRect(0,0,canvas.width,canvas.height);
    ctx.fillStyle = "white";
    ctx.fillText ("Hello World",canvas.width/2,canvas.height*.8);
    }
}
</script>
</head>
<body onload="draw()" bgcolor="lightgray" >
      <div>
        <canvas id="MyCanvas" width="500" height="500" > </canvas>
      </div>
  </body>
</html>
Notes Remarks

The getContext method returns null if the contextId value is not supported.

Syntax Standards information See also Related pages 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