Canvas part 1

HTML Fundamentals
HTML5
Canvas
18
1/3
               

The <canvas> Element



The HTML canvas is used to draw graphics that include everything from simple lines to complex graphic objects.

The <canvas> element is defined by:<canvas id="canvas1" width="200" height="100">
</canvas>

The <canvas> element is only a container for graphics. You must use a script to actually draw the graphics (usually JavaScript).
The <canvas> element must have an id attribute so it can be referred to by JavaScript:<html>
<head></head>
<body>
<canvas id="canvas1"
width="400" height="300"></canvas>
<script>
var can = document.getElementById("canvas1");
var ctx = can.getContext("2d");
</script>

</body>
</html>

getContext() returns a drawing context on the canvas.
Basic knowledge of JavaScript is required to understand and use the Canvas.

Comments

Popular posts from this blog

Drag&Drop API