Home > Web Front-end > HTML Tutorial > HTML5 Canvas

HTML5 Canvas

(*-*)浩
Release: 2019-10-24 15:11:49
Original
2236 people have browsed it

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

HTML5 Canvas

What is Canvas?

HTML5’s canvas element uses JavaScript to draw images on a web page. (Recommended learning: html tutorial)

The canvas is a rectangular area, and you can control every pixel of it.

canvas has many ways to draw paths, rectangles, circles, characters, and add 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>
Copy after login

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template