HTML5 Canvas ( 文字的書寫和樣式控制 ) font, fillText, strokeText

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.