<canvas>
element is used to draw graphics, on the fly, on a web page.
The element is only a container for graphics.
You must use a script (usually JavaScript) to actually draw the graphics.
<canvas>
element.
The markup looks like this:
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;"></canvas>
<script> var c = document.getElementById( "myCanvas" ); var ctx = c.getContext( "2d" ); ctx.fillStyle = "#FF0000"; ctx.fillRect( 0, 0, 150, 75 ); </script>
<canvas>
element:
var c = document.getElementById( "myCanvas" );
getContext( )
method, which is a built-in HTML5 object, with many properties and methods for drawing graphics:
var ctx = c.getContext( "2d" );
fillRect(x,y,w,h)
method draws a rectangle filled with the current fill style and the fillStyle
property can be a CSS color, a gradient, or a pattern.
ctx.fillStyle = "#FF0000"; ctx.fillRect( 0, 0, 150, 75 );
|
Review: HTML5 Canvas |
Which statement is NOT true about HTML5 Canvas?
JavaScript is usually used by HTML5 canvas to draw graphics. The <canvas> element is used to draw graphics on a web page.The <canvas> element is only a container for graphics. |
Result: |