zoukankan      html  css  js  c++  java
  • [ html canvas 绘制文本 ] canvas绘图实现绘制文本 strokeText fillText方法及textAlign textBaseline font 属性实例演示

     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>
  • 相关阅读:
    (转)Apache与Tomcat 区别联系
    (转)JAVA排序汇总
    (转)Java线程:大总结
    (转)Java线程:新特征-原子量,障碍器
    (转)Java线程:新特征-条件变量
    oracle中的not in和not exists注意事项
    oracle字符乱码的解决方法
    线刷和卡刷的区别
    nexus5刷机
    linux上复制行到另一个文件
  • 原文地址:https://www.cnblogs.com/mysearchblog/p/5771012.html
Copyright © 2011-2022 走看看