HTML5 Canvas Implementation Method:

Source: Internet
Author: User

We can use the property width and height in HTML to define the canvas. However, the implementation of canvas's related functions is mainly dependent on the JavaScript implementation, that is, the HTML5 canvas API. We use JavaScript to access and control canvas-related areas, such as the method of invoking related drawings, to dynamically generate the desired animation or graphics.

HTML5 introduces a new <canvas> tag that represents the area as if it were a canvas, and all the graphics are drawn at the end of the canvas.

<canvas id= "Tutorial" width= "Zi" height= "style=" > <p> if you see this line, your browser does not support canvas tags </p> </ Canvas>
Note: If you do not specify width and height in HTML, the default height is 300px and the width is 150px.


HTML5 Canvas has a lot of cool features:

1. Interactivity: Canvas supports interaction and can respond well to user actions, and we can use JavaScript to monitor keyboard, mouse, and touch device related events.

2. Animations: Any canvas-drawn graphics can be animated, a simple bouncing ball or a complex HTML5 game can be achieved

3. Flexibility: Developers can use canvas to draw any content, such as lines, graphics, text, pictures and so on, can contain animations or not included. You can also add audio or video

4. Browser support: Almost all modern browsers are supported, and are supported by a wide variety of devices, such as desktop, tablet, smartphone and so on.

5. Popularity: Canvas is currently popular, and many developers use it to develop similar games or drawing applications

6.web Standard: Only need to have a browser to run, not flash or Silverlight, needs to install the relevant plug-in

7. Developed once, any browser can run (of course, not including the old browser)

8. Use a large number of development tools and libraries for free

Using HTML CANVAS:

Using HTML5 canvas is actually very simple, and each canvas has a context. You can use it to invoke the relevant canvas method.

where 2D types of graphics need to call 2D context,3d the need to invoke 3D graphics related to the context (this is usually called WebGL).

1. getcontext(' 2d '); Take the context of 2D. You use jquery, you can use the following code to get the context:$("#mycanvas") [0]. GetContext(' 2d ');

2. Use HTML5 Canvas to draw many types of graphics, including lines, curves, paths, shapes, text, etc.;

HTML5 Canvas Implementation Method:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.