is a new tag in HTML5, used for drawing graphics. This article mainly introduces the basic drawing method of HTML5 canvas to draw rectangles in detail. Interested friends can For reference
is just a container for drawing graphics. In addition to attributes such as id, class, style, etc., it also has height and width attributes. There are three main steps for drawing on the
1. Get the DOM object corresponding to the
Draw rectangles rect(), fillRect() and strokeRect()
•context.rect(x, y, width, height): only define the path of the rectangle ;
•context.fillRect( x , y , width , height ): directly draw a filled rectangle;
•context.strokeRect( x , y , width , height ): directly draw a rectangular border;
JavaScript CodeCopy content to clipboard
There is another one related to rectangular drawing: clearing the rectangular area: context.clearRect(x,y,width,height).
The received parameters are: clear the starting position of the rectangle and the width and length of the rectangle.In the above code, add at the end of drawing the graphics:
context.clearRect(100,60,600,100);
The following effect can be obtained:
The above is the detailed content of HTML5 canvas basic drawing: drawing rectangle. For more information, please follow other related articles on the PHP Chinese website!