[ html canvas 繪製文本 ] canvas繪圖實現繪製文本 strokeText fillText方法及textAlign textBaseline font 屬性執行個體示範

來源:互聯網
上載者:User

標籤:

 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>

 

[ html canvas 繪製文本 ] canvas繪圖實現繪製文本 strokeText fillText方法及textAlign textBaseline font 屬性執行個體示範

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.