"."/> ".">

Home >Web Front-end >Front-end Q&A >What is html canvas

What is html canvas

WBOY
WBOYOriginal
2022-03-28 11:47:591882browse

html canvas is an html rectangular area on which graphics can be drawn. Each pixel can be controlled. A canvas can be added to the page through the canvas element. The syntax is "6c89e8442251c51773b19b3f3e297de4c2caaf3fc160dd2513ce82f021917f8b".

What is html canvas

The operating environment of this article: Windows 10 system, html5 version, Dell G3 computer.

What is html canvas

The canvas is an HTML area on which graphics can be drawn.

The canvas element is used to draw graphics on web pages.

The canvas element of HTML5 uses JavaScript to draw images on the web page.

The canvas is a rectangular area that you can control every pixel of.

canvas has a variety of methods for drawing paths, rectangles, circles, characters, and adding images.

Create Canvas element

Add canvas element to HTML5 page.

Specify the id, width and height of the element:

<canvas id="myCanvas" width="200" height="100"></canvas>

Draw through JavaScript

The canvas element itself has no drawing capabilities. All drawing work must be done inside JavaScript:

<script type="text/javascript">
var c=document.getElementById("myCanvas");
var cxt=c.getContext("2d");
cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);
</script>

JavaScript uses id to find the canvas element:

var c=document.getElementById("myCanvas");

Then, create the context object:

var cxt=c.getContext("2d");

getContext("2d" ) object is a built-in HTML5 object with multiple methods for drawing paths, rectangles, circles, characters, and adding images.

The following two lines of code draw a red rectangle:

cxt.fillStyle="#FF0000";
cxt.fillRect(0,0,150,75);

The fillStyle method dyes it red, and the fillRect method specifies the shape, position, and size.

Recommended tutorial: "html video tutorial"

The above is the detailed content of What is html canvas. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn