HTML canvas fillText() နည်းလမ်း
ဥပမာ
"Hello world!" ဟုရေးပါ။ နှင့် "အပြုံးကြီး!" fillText():
JavaScript-
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);
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် နည်းလမ်းကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးသည်။
Method | |||||
---|---|---|---|---|---|
fillText() | 4.0 | 9.0 | 3.6 | 4.0 | 10.1 |
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
fillText() method သည် canvas ပေါ်တွင် ဖြည့်ထားသော စာသားကို ဆွဲသည်။ စာသား၏ မူရင်းအရောင်မှာ အနက်ရောင်ဖြစ်သည်။
အကြံပြုချက်- ဖောင့်နှင့် ဖောင့်အရွယ်အစားကို သတ်မှတ်ရန် ဖောင့်ပိုင်ဆိုင်မှုကို အသုံးပြုပြီး စာသားကို အခြား အရောင်/အရောင်ပြောင်းရန် fillStyle ပိုင်ဆိုင်မှုကို အသုံးပြုပါ။
JavaScript syntax- | ဆက်စပ်အကြောင်းအရာ .fillText( စာသား၊ 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 |
❮ Canvas Object