హ్ట్మ్ల్ కాన్వాస్ టెక్స్ట్

కాన్వెక్స్ పైన పదాలు రాయండి

కాన్వెక్స్ పైన పదాలు రాయండి అనేది అత్యంత ముఖ్యమైన అంశం మరియు పద్ధతులు ఉన్నాయి:

  • font - పదాల ఫాంట్ అంశాలను నిర్వహించడం
  • fillText(text,x,y) - కాన్వెక్స్ పైన "ఫిల్ల్ చేసిన" పదాలు రాయండి
  • strokeText(text,x,y) - కాన్వెక్స్ పైన పదాలు రాయండి (ఫిల్ల్ కాదు)

fillText() ఉపయోగించండి

ఉదాహరణ

ఫాంట్ని "30px Arial" గా సెట్ చేయండి మరియు కాన్వెక్స్ పైన పదాలు రాయండి (ఫిల్ల్ చేయండి):

మీ బ్రౌజర్ హెచ్ఎంఎల్5 కాన్వెక్స్ టాగ్ ను మద్దతు ఇవ్వలేదు.

జావాస్క్రిప్ట్:

const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
ctx.fillText("హలో వరల్డ్", 10, 50);

亲自试一试

strokeText() ఉపయోగించండి

ఉదాహరణ

ఫాంట్ని "30px Arial" గా సెట్ చేయండి మరియు కాన్వెక్స్ పైన పదాలు రాయండి (ఫిల్ల్ కాదు):

మీ బ్రౌజర్ హెచ్ఎంఎల్5 కాన్వెక్స్ టాగ్ ను మద్దతు ఇవ్వలేదు.

జావాస్క్రిప్ట్:

const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.font = "30px Arial";
ctx.strokeText("హలో వరల్డ్", 10, 50);

亲自试一试

రంగును జోడించి మధ్యలో వచ్చే పదాలు

ఉదాహరణ

ఫాంట్ని "30px Comic Sans MS" గా సెట్ చేయండి మరియు కాన్వెక్స్ మధ్యలో రెడ్ రంగుతో రాయండి:

మీ బ్రౌజర్ హెచ్ఎంఎల్5 కాన్వెక్స్ టాగ్ ను మద్దతు ఇవ్వలేదు.

జావాస్క్రిప్ట్:

const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
ctx.font = "30px Comic Sans MS";
ctx.fillStyle = "red";
ctx.textAlign = "center";
ctx.fillText("హలో వరల్డ్", canvas.width/2, canvas.height/2);

亲自试一试

另请参阅:

CodeW3C.com 的完整 Canvas 参考手册