طريقة تعبئة النص في لوحة HTML ()

❮ مرجع قماش HTML

مثال

اكتب "Hello world!" و "ابتسامة كبيرة!" (مع التدرج) على اللوحة القماشية ، باستخدام fillText ():

لا يدعم متصفحك HTML5canvastag.

جافا سكريبت:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

ctx.font = "20px Georgia";
ctx.fillText("Hello World!", 10, 50);

ctx.font = "30px Verdana";
// Create gradient
var gradient = ctx.createLinearGradient(0, 0, c.width, 0);
gradient.addColorStop("0"," magenta");
gradient.addColorStop("0.5", "blue");
gradient.addColorStop("1.0", "red");
// Fill with gradient
ctx.fillStyle = gradient;
ctx.fillText("Big smile!", 10, 90);

دعم المتصفح

تحدد الأرقام الواردة في الجدول إصدار المتصفح الأول الذي يدعم الطريقة بالكامل.

Method
fillText() Yes 9.0 Yes Yes Yes

ملاحظة: لا يتم دعم معلمة maxWidth في Safari 5.1 والإصدارات السابقة.


التعريف والاستخدام

تقوم طريقة fillText () برسم النص المعبأ على اللوحة القماشية. اللون الافتراضي للنص هو الأسود.

تلميح: استخدم خاصية الخط لتحديد الخط وحجم الخط ، واستخدم خاصية نمط التعبئة لعرض النص بلون / تدرج آخر.

بناء جملة JavaScript: السياق .fillText ( text، x، y، maxWidth ) ؛

قيمه المعامل

Parameter Description Play it
text Specifies the text that will be written on the canvas
x The x coordinate where to start painting the text (relative to the canvas)
y The y coordinate where to start painting the text (relative to the canvas)
maxWidth Optional. The maximum allowed width of the text, in pixels

❮ مرجع قماش HTML