A RetroSearch Logo

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

Search Query:

Showing content from https://webplatform.github.io/docs/canvas/properties/width below:

width ยท WebPlatform Docs

width Summary

Width property of canvas element.

Property of dom/HTMLCanvasElementdom/HTMLCanvasElement

Syntax
var result = element.width;
element.width = value;
Examples

The following code example uses the width and height property to get and set the attributes of a canvas element on the document.

<!DOCTYPE html>
<head>
  <script type="text/javascript">
function draw()
{
  var canvas = document.getElementById("MyCanvas");
  if (canvas.getContext)
    {
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "blue";
    ctx.fillRect(0,0,canvas.width,canvas.height);
    }
}
function change(val)
    {
    var canvas = document.getElementById("MyCanvas");
    canvas.width = canvas.width + val;
    canvas.height = canvas.height + val;
    draw();
    }
  </script>
</head>
<body onload="draw()" bgcolor="lightgray" >
      <div>
      <button onclick="change(10)">Make canvas larger</button>
      <button onclick="change(-10)">Make canvas smaller</button>
      </div>
      <div>
        <canvas id="MyCanvas" width="500" height="500" > </canvas>
      </div>
  </body>
</html>
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