my.createCanvasContext

Create canvas context This canvas context works on the <canvas/> of the corresponding canvasId only.

Parameters

PropertyTypeDescription
canvasIdStringID defined on the <canvas/>.

Return Value

CanvasContext

Sample Code

copy
//.js
const ctx = my.createCanvasContext('myCanvas')

const grd = ctx.createLinearGradient(30, 10, 120, 10)
grd.addColorStop(0, 'red')
grd.addColorStop(0.16, 'orange')
grd.addColorStop(0.33, 'yellow')
grd.addColorStop(0.5, 'green')
grd.addColorStop(0.66, 'cyan')
grd.addColorStop(0.83, 'blue')
grd.addColorStop(1, 'purple')

// Fill color
ctx.setFillStyle(grd)
ctx.fillRect(10, 10, 150, 80)
ctx.draw()