Lastnost fillStyle

Lastnost fillStyle določa barvo zapolnitve figure pri risanju na canvas. Vrednostjo lastnosti so katere koli CSS enote za barvo.

Sintaksa

javascriptkontekst.fillStyle = barva;

Primer

Narišimo kvadrat s pomočjo rect in ga zapolnimo z rdečo barvo:

html<canvas id="canvas" width="200" height="200" style="background: #f4f4f4;"></canvas>
javascriptlet canvas = document.querySelector('#canvas');
let ctx = canvas.getContext('2d');

ctx.rect(50, 50, 100, 100);
ctx.fillStyle = 'red';
ctx.fill();

Результат:

Glejte tudi