1<! DOCTYPE html>234<title>insert you title</title>5<meta name= ' description ' content= ' This is my page ' >6<meta name= ' keywords ' content= ' keyword1,keyword2,keyword3 ' >7<meta http-equiv= ' content-type ' content= ' text/html; Charset=utf-8 ' >8<link rel= ' stylesheet ' type= ' text/css ' href= './css/index.css '/>9<script type= ' text/javascript ' src= './js/jquery-1.12.1.min.js ' ></script>Ten<style type= ' text/css ' > One Html,body,canvas { Amargin:0; padding:0; - } - the HTML { -height:100% - } - + Body { -Background: #000; + } A at #can { -Background: #FFF; Display:block; MARGIN:25PX Auto; border-radius:2px;line-height:0; - } -</style> -<script type= ' Text/javascript ' > -$(function(){ in varcan = $ (' #can '). Get (0 ); - varOcan = Can.getcontext (' 2d ' ); to varW =Can.width; + varh =Can.height; -Ocan.font = ' 50px in italics ';/*Font size is indispensable*/ theOcan.stroketext (' Lattice ', 200, 175 ); *Ocan.font = ' 50px Courier New ';/*can be added bold but the font size is integral and is populated in different ways to change the font*/ $Ocan.strokestyle = ' #F00 ';Panax Notoginsengocan.textalign = ' center '/*Set the horizontal center mode*/ -Ocan.textbaseline = ' Middle ';/*Set Vertical Center mode*/ the varText = ' chuangling '; +Ocan.filltext (text, W/2, H/2);/*Create adaptive centering of text*/ AAlert (Ocan.measuretext (text). width);/*you can get the actual width value of the text, only the width measure: Measurement*/ the } ); +</script> - $<body> $<canvas id= ' can ' width= ' height= ' > detects that your browser version is too low please upgrade your browser version to get a better experience with it ...</canvas> -</body> -
[HTML canvas font textAlign textbaseline measuretext (). Width] Canvas Drawing properties Font textAlign textbaseline measuretext (). Width Properties Demo