HTML 5 canvas textBaseline ÊôÐÔ
ʵÀý
¶¨ÒåÓÃÀ¶É«Ìî³äµÄ¾ØÐΣº
JavaScript:
var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); //ÔÚλÖà y=100 »æÖÆÀ¶É«ÏßÌõ ctx.strokeStyle="blue"; ctx.moveTo(5,100); ctx.lineTo(395,100); ctx.stroke(); ctx.font="20px Arial" //ÔÚ y=200 ÒÔ²»Í¬µÄ textBaseline Öµ·ÅÖÃÿ¸öµ¥´Ê ctx.textBaseline="top"; ctx.fillText("Top",5,100); ctx.textBaseline="bottom"; ctx.fillText("Bottom",50,100); ctx.textBaseline="middle"; ctx.fillText("Middle",120,100); ctx.textBaseline="alphabetic"; ctx.fillText("Alphabetic",190,100); ctx.textBaseline="hanging"; ctx.fillText("Hanging",290,100);
ä¯ÀÀÆ÷Ö§³Ö
Internet Explorer 9¡¢Firefox¡¢Opera¡¢Chrome ÒÔ¼° Safari Ö§³Ö textBaseline ÊôÐÔ¡£
×¢ÊÍ£ºInternet Explorer 8 ÒÔ¼°¸üÔçµÄ°æ±¾²»Ö§³Ö <canvas> ÔªËØ¡£
¶¨ÒåºÍÓ÷¨
textBaseline ÊôÐÔÉèÖûò·µ»ØÔÚ»æÖÆÎı¾Ê±µÄµ±Ç°Îı¾»ùÏß¡£
ÏÂÃæµÄͼʾÑÝʾÁË textBaseline ÊôÐÔÖ§³ÖµÄ¸÷ÖÖ»ùÏߣº

×¢ÊÍ£ºfillText() »ò strokeText() ·½·¨ÔÚ»²¼É϶¨Î»Îı¾Ê±£¬½«Ê¹ÓÃÖ¸¶¨µÄ textBaseline Öµ¡£
ĬÈÏÖµ£º | alphabetic |
---|---|
JavaScript Óï·¨£º | context.textBaseline="alphabetic|top|hanging|middle|ideographic|bottom"; |
ÊôÐÔÖµ
Öµ | ÃèÊö |
---|---|
alphabetic | ĬÈÏ¡£Îı¾»ùÏßÊÇÆÕͨµÄ×Öĸ»ùÏß¡£ |
top | Îı¾»ùÏßÊÇ em ·½¿òµÄ¶¥¶Ë¡£¡£ |
hanging | Îı¾»ùÏßÊÇÐü¹Ò»ùÏß¡£ |
middle | Îı¾»ùÏßÊÇ em ·½¿òµÄÕýÖС£ |
ideographic | Îı¾»ùÏßÊDZíÒâ»ùÏß¡£ |
bottom | Îı¾»ùÏßÊÇ em ·½¿òµÄµ×¶Ë¡£ |