HTML5 Concise tutorial -1.1.4.html5canvas linear gradient createlineargradient of the reference manual

Source: Internet
Author: User

This article connects: http://blog.csdn.net/tomorrow13210073213/article/details/42453769

Reprint please indicate the source


HTML5 's canvas provides us with a gradient effect similar to the Linear-gradient attribute definition in CSS3, which allows you to create a linear gradient based on the canvas using the Createlineargradient () method, which creates a linear gradient that can be used to fill the path, Define strokes, and so on. At the same time, HTML5 also provided us with a createradialgradient () method for creating a radial gradient, which we'll cover in detail in another blog post.


Method: Createlineargradient ()

Method Name: Createlineargradient ()

Method Description: Used to create a linear gradient based on the entire canvas, which can be used to fill a path or define a stroke (as the value of an attribute FillStyle or Strokestyle)

JS Syntax: context.createlineargradient (X0,Y0,X1,Y1);
Parameter: x0: The x-coordinate of the start point of the gradient,
Parameter: y0: The y-coordinate of the start point of the gradient,
Parameter: X1: The x-coordinate of the gradient end point,
Parameter: y1: the y-coordinate of the gradient end point

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

Note: (1) After getting the gradient object, we use the Addcolorstop () method to specify a different color and where to position the color in the gradient object. Another blog post is detailed on this approach.

(2) The gradient we define with the Createlineargradient () method is based on the entire canvas, and is not visible simply by defining the gradient, which is defined as the value of the property fillstyle or Strokestyle. We are actually showing the gradient of the path-defined rectangle (face or stroke), circle (face or stroke) section.


No more nonsense, here is the test code, JS comments have a description of the relevant test:

<! DOCTYPE html>
Here is the test:

(Pictures don't come up ah, csdn, let's test it yourself)


HTML5 Concise tutorial -1.1.4.html5canvas linear gradient createlineargradient of the reference manual

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.