HTML canvas textAlign Property
ဥပမာ
အနေအထား 150 တွင် အနီရောင်မျဉ်းတစ်ကြောင်း ဖန်တီးပါ။ ရာထူး 150 သည် အောက်ဖော်ပြပါ ဥပမာတွင် သတ်မှတ်ထားသော စာသားအားလုံးအတွက် ကျောရိုးအမှတ်ဖြစ်သည်။ textAlign ပိုင်ဆိုင်မှုတန်ဖိုးတစ်ခုစီ၏အကျိုးသက်ရောက်မှုကိုလေ့လာပါ-
JavaScript-
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
// Create a red line in position 150
ctx.strokeStyle = "red";
ctx.moveTo(150, 20);
ctx.lineTo(150, 170);
ctx.stroke();
ctx.font = "15px Arial";
// Show the different textAlign values
ctx.textAlign = "start";
ctx.fillText("textAlign=start", 150, 60);
ctx.textAlign = "end";
ctx.fillText("textAlign=end", 150, 80);
ctx.textAlign = "left";
ctx.fillText("textAlign=left", 150, 100);
ctx.textAlign = "center";
ctx.fillText("textAlign=center", 150, 120);
ctx.textAlign = "right";
ctx.fillText("textAlign=right", 150, 140);
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် ပိုင်ဆိုင်မှုကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးသည်။
Property | |||||
---|---|---|---|---|---|
textAlign | Yes | 9.0 | Yes | Yes | Yes |
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
textAlign ပိုင်ဆိုင်မှုသည် anchor point အရ စာသားအကြောင်းအရာအတွက် လက်ရှိချိန်ညှိမှုကို သတ်မှတ် သို့မဟုတ် ပြန်ပေးသည်။
ပုံမှန်အားဖြင့်၊ စာသားသည် သတ်မှတ်ထားသည့် အနေအထားတွင် စတင်မည်ဖြစ်သော်လည်း၊ သင်သည် textAlign ="right" ကို သတ်မှတ်ပြီး စာသားကို ရာထူး 150 တွင် ထားပါက၊ စာသားသည် ရာထူး 150 တွင် ပြီးဆုံးသင့် သည်ဟု ဆိုလိုသည် ။
အကြံပြုချက်- fillText () သို့မဟုတ် strokeText() နည်းလမ်းကို အသုံးပြု၍ ကင်းဗတ်စ်ပေါ်တွင် စာသားကို အမှန်တကယ်ဆွဲပြီး နေရာချထားပါ။
မူလတန်ဖိုး: | စတင်ပါ။ |
---|---|
JavaScript syntax- | စကား စပ် .textAlign="center|end|left|right|start"; |
အိမ်ခြံမြေတန်ဖိုးများ
Values | Description | Play it |
---|---|---|
start | Default. The text starts at the specified position | |
end | The text ends at the specified position | |
center | The center of the text is placed at the specified position | |
left | The text starts at the specified position | |
right | The text ends at the specified position |
❮ HTML Canvas အကိုးအကား