Font property

Die font property stel die lettertipe-instellings in wanneer dit op canvas geteken word met die metode fillText of die metode strokeText. Die metode aanvaar dieselfde parameters as die CSS property font.

Sintaksis

javascriptkonteks.font = lettertipe instellings;

Voorbeeld

Kom ons teken teks op canvas met behulp van fillText en stel die grootte in op 30px en die tipe Arial met behulp van font:

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

ctx.font = '30px Arial';
ctx.fillText('Hello world', 30, 50);

Результат:

Sien ook