Simple HTML5 tutorial-1.1.4.HTML5Canvas reference manual-linear gradient createLinearGradient, html5canvas

Source: Internet
Author: User

Simple HTML5 tutorial-1.1.4.HTML5Canvas reference manual-linear gradient createLinearGradient, html5canvas

Connection: http://blog.csdn.net/tomorrow13210073213/article/details/42453769

Reprinted please indicate the source


HTML5 canvas provides a gradient effect similar to the linear-gradient attribute defined in CSS3. You can use createLinearGradient () to create a canvas-based linear gradient, the created linear gradient can be used to fill the path and define strokes. At the same time, HTML5 provides the createRadialGradient () method for creating a radiation gradient. We will introduce it in detail in another blog.


Method: createLinearGradient ()

Method Name: createLinearGradient ()

Method Description: used to create a linear gradient based on the entire canvas. The gradient can be used to fill the path or define the stroke (as the value of the attribute fillStyle or strokeStyle)

Js Syntax: context. createLinearGradient (x0, y0, x1, y1 );
Parameter: x0: x coordinate of the gradient start point,
Parameter: y0: y coordinate of the gradient start point,
Parameter: x1: x coordinate of the gradient end point,
Parameter: y1: y coordinate of the gradient end point

Browser compatibility: IE 9, Firefox, Opera, Chrome, and Safari support the createLinearGradient () method.

Note: (1) After obtaining the gradient object, we need to use the addColorStop () method to specify different colors and where to locate the color in the gradient object. This method is described in another blog.

(2) The gradient defined using the createLinearGradient () method is based on the entire canvas. It is invisible only by defining the gradient. After defining the gradient as the value of the fillStyle or strokeStyle attribute, we actually show the gradient of the rectangle (surface or stroke) and circle (surface or stroke) defined by the path.


The following is the test code. The js comments contain the test description:

<! DOCTYPE html> 

The following is a test:

(The image cannot be uploaded. What about csdn? Let's test it by yourself)


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.