طريقة HTML canvas strokeText ()

❮ مرجع قماش HTML

مثال

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

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

جافا سكريبت:

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

ctx.font = "20px Georgia";
ctx.strokeText("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.strokeStyle = gradient;
ctx.strokeText("Big smile!", 10, 90);

دعم المتصفح

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

Method
strokeText() Yes 9.0 Yes Yes Yes

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


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

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

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

بناء جملة JavaScript: السياق .strokeText ( 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