1 <!DOCTYPE html>
2 <html lang='zh-cn'>
3 <head>
4 <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>
10 <style type='text/css'>
11 html,body { 12 margin: 0; padding: 0; 13 } 14
15 html { 16 background: #999; 17 } 18
19 #can { 20 background: #FFF; display: block; margin: 75px auto; border-radius: 2px; 21 } 22 </style>
23 <script type='text/javascript'>
24 $( function(){ 25 var oCan = $( '#can' ).get( 0 ).getContext( '2d' ); 26 oCan.beginPath(); 27
28 /*
29
30 oCan.strokeText(text,x,y) 和 oCan.fillText(text,x,y)之間的區別: 31 實心和空心字體之間的區別; 32
33 oCan.font : 設置字體樣式和大小 34
35 oCan.textAlign : 設置文本在基線上的水平對齊方式 36
37 oCan.textBaseLine : 設置文本在垂直方向上的對齊方式 38
39
40
41 */
42
43 oCan.font = '900 40px Microsoft yahei'; /* 這個屬性和 旋轉 縮放 平移一樣是需要設置在前面的否則無效 並且字體大小和字體樣式缺一不可*/
44 oCan.lineWidth = 1; 45 oCan.strokeStyle = '#F00'; 46 oCan.textAlign = 'center'; /* 在基線的水平位置上實現屬性值 left right start center end */
47 oCan.textBaseline = 'bottom'; /* 在基線的垂直位置上實現屬性值 top bottom middle hanging...*/
48 oCan.strokeText( '窗欞老師好帥xem' , 250 , 250 ); /* 設置空心字體 */
49 oCan.arc( 250 , 250 , 2 , 0 , 2 * Math.PI , false ); 50 oCan.fillText( '窗欞老師好帥' , 30 , 300 ); /* 設置實心填充字體 */
51 oCan.stroke(); 52 oCan.closePath(); 53 } ); 54 </script>
55 </head>
56 <body>
57 <canvas id='can' width='500' height='500'>您的瀏覽器版本過低,請升級您的瀏覽器版本以獲取更好的用戶體驗...</canvas>
58 </body>
59 </html>