<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "UTF-8"> <title>Canvas</title> <Scripttype= "text/javascript"src=".. /js/jquery.js "></Script> <styletype= "text/css"> *{margin:0;padding:0;Outline:None;Border:None; }#canvas{width:7rem;margin:. 25rem 0 0 1.5rem;Border:1px solid Black; } </style></Head><Body> <CanvasID= "canvas"width= "+"Height= "all"></Canvas></Body></HTML><Scripttype= "text/javascript"> /** * REM Layout initialization*/ $('HTML'). css ('font-size', $ (window). width ()/( ten); /** Get canvas Canvas * Get canvas drawing context*/ varCanvas= $('#canvas')[0]; varCXT=Canvas.getcontext ('2d'); /** * Text alignment * Textalign:left Center right*/ /*Cxt.fillstyle = "blue"; Cxt.font = "bold 40px sans-serif"; Cxt.textalign = "left"; Cxt.filltext ("Hello Canvas", 500, 200); Cxt.textalign = "center"; Cxt.filltext ("Hello Canvas", 500, 300); Cxt.textalign = "right"; Cxt.filltext ("Hello Canvas", 500, 400); Cxt.moveto (500, 0); Cxt.lineto (500, 600); Cxt.stroke (); */ /** Text alignment * textbaseline:top, middle, bottom, alphabetic (latin text), ideographic (kanji), hanging (indic Text)*/Cxt.fillstyle= "Blue"; Cxt.font= "Bold 40px Sans-serif"; Cxt.textbaseline= "Top"; Cxt.filltext ("Hello Canvas", -, -); Cxt.textbaseline= "Middle"; Cxt.filltext ("Hello Canvas", -, -); Cxt.textbaseline= "Bottom"; Cxt.filltext ("Hello Canvas", -, -); Cxt.moveto (0, -); Cxt.lineto ( +, -); Cxt.moveto (0, -); Cxt.lineto ( +, -); Cxt.moveto (0, -); Cxt.lineto ( +, -); Cxt.stroke ();</Script>
HTML5 Canvas (text Horizontal vertical Alignment) textAlign, textbaseline