码迷,mamicode.com
首页 > Web开发 > 详细

HTML5 Canvas ( 文字的书写和样式控制 ) font, fillText, strokeText

时间:2017-03-30 00:08:26      阅读:356      评论:0      收藏:0      [点我收藏+]

标签:normal   ack   var   jquer   上下文   code   lte   区别   大小   

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>canvas</title>
    <script type="text/javascript" src="../js/jQuery.js"></script>
    <style type="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> 
    <canvas id="canvas" width="1000" height="600"></canvas>
</body>
</html>
<script type="text/javascript">
    /**
     * rem 布局初始化
     */
    $(html).css(font-size, $(window).width()/10);
    /**
     * 获取 canvas 画布
     * 获取 canvas 绘图上下文环境
     */
    var canvas = $(#canvas)[0];
    var cxt = canvas.getContext(2d);
    
    /**
     * 文字的书写
     * fillText(要写的文字, 文字开始的横坐标, 文字开始的纵坐标, 文字占用的最长宽度)
     * strokeText(要写的文字, 文字开始的横坐标, 文字开始的纵坐标, 文字占用的最长宽度)
     * font 字体大小和样式
     */
    
    /*
     * font参数的值分为
     * font-style: normal(正常), italic(斜体字), oblique(倾斜字体) 后两种在网页端一般没什么区别
     * font-variant: normal(正常), small-caps(英文小写字母变成小的大写)
     * font-weight: normal(正常), bold(加粗) 100-900(一般不用)
     * font-size: 文字大小
     * font-family: 字体样式
     */
    cxt.font = "oblique small-caps bold 50px Arial";
    
    cxt.fillStyle = "blue";
    cxt.fillText("Hello Canvas!" ,100, 100, 200);
    
    cxt.strokeStyle = blue;    
    cxt.strokeText("Hello Canvas!", 100, 300, 200);
</script>

 

HTML5 Canvas ( 文字的书写和样式控制 ) font, fillText, strokeText

标签:normal   ack   var   jquer   上下文   code   lte   区别   大小   

原文地址:http://www.cnblogs.com/lovling/p/6642436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!