/

HTML / CSS / JavaScript Tutorial

JavaScript canvas2d object method: createLinearGradient()

[this page | pdf | back links]

The createLinearGradient() method of the JavaScript DOM object returned by the getContext("2d") method applied to the HTML <canvas> element creates a linear gradient. The resulting object can be used as the value of the strokeStyle or fillStyle properties and hence to fill in rectangles, circles etc. You need to apply some addColorStop() methods to the gradient for it to be visible.

 

It has the following syntax with the following parameters.

 

context.createLinearGradient(xstart, ystart, xend, yend)

 

Parameter

Required / Optional

Description

xstart

Required

x-coordinate of gradient start point

xend

Required

y-coordinate of gradient start point

ystart

Required

x-coordinate of gradient end point

yend

Required

y-coordinate of gradient end point

 


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile