HTML 5 canvas textAlign ÊôÐÔ
ʵÀý
ÔÚλÖà 150 ´´½¨Ò»ÌõºìÏß¡£Î»Öà 150 ÊÇÏÂÃæÀý×ÓÖж¨ÒåµÄËùÓÐÎı¾µÄêµã¡£ÇëÑо¿Ã¿ÖÖ textAlign ÊôÐÔÖµµÄЧ¹û£º
JavaScript:
var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); // ÔÚλÖà 150 ´´½¨À¶Ïß ctx.strokeStyle="blue"; ctx.moveTo(150,20); ctx.lineTo(150,170); ctx.stroke(); ctx.font="15px Arial"; // ÏÔʾ²»Í¬µÄ textAlign Öµ 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);
ä¯ÀÀÆ÷Ö§³Ö
Internet Explorer 9¡¢Firefox¡¢Opera¡¢Chrome ÒÔ¼° Safari Ö§³Ö textAlign ÊôÐÔ¡£
×¢ÊÍ£ºInternet Explorer 8 ÒÔ¼°¸üÔçµÄ°æ±¾²»Ö§³Ö <canvas> ÔªËØ¡£
¶¨ÒåºÍÓ÷¨
textAlign ÊôÐÔ¸ù¾Ýêµã£¬ÉèÖûò·µ»ØÎı¾ÄÚÈݵĵ±Ç°¶ÔÆë·½Ê½¡£
ͨ³££¬Îı¾»á´ÓÖ¸¶¨Î»ÖÿªÊ¼£¬²»¹ý£¬Èç¹ûÄúÉèÖÃΪ textAlign="right" ²¢½«Îı¾·ÅÖõ½Î»Öà 150£¬ÄÇô»áÔÚλÖà 150 ½áÊø¡£
Ìáʾ£ºÊ¹Óà fillText() »ò strokeText() ·½·¨ÔÚʵ¼ÊµØÔÚ»²¼ÉÏ»æÖƲ¢¶¨Î»Îı¾¡£
ĬÈÏÖµ£º | start |
---|---|
JavaScript Óï·¨£º | context.textAlign="center|end|left|right|start"; |
ÊôÐÔÖµ
Öµ | ÃèÊö |
---|---|
start | ĬÈÏ¡£Îı¾ÔÚÖ¸¶¨µÄλÖÿªÊ¼¡£ |
end | Îı¾ÔÚÖ¸¶¨µÄλÖýáÊø¡£ |
center | Îı¾µÄÖÐÐı»·ÅÖÃÔÚÖ¸¶¨µÄλÖᣠ|
left | Îı¾×ó¶ÔÆë¡£ |
right | Îı¾ÓÒ¶ÔÆë¡£ |