canvas--改變顏色


代碼:

 1 <canvas id="c1" width="400" height="400" style="background-color:red">
 2     </canvas>
 3 
 4     <script type="text/javascript">
 5         //獲取畫布元素
 6         var canvas=document.getElementById("c1");
 7         //繪制環境(我稱為“畫筆”)
 8         var cxt=canvas.getContext("2d");
 9         
10         //改變填充的顏色
11         cxt.fillStyle="#ffff00";
12         //畫一個實體方塊---fillrect(x,y,w,h);
13         cxt.fillRect(50,50,100,100);
14         
15         //改變邊框顏色
16         cxt.strokeStyle="blue";
17         //改變邊框寬度
18         cxt.lineWidth=5;
19         //畫出一個空心方塊---strokeRect(x,y,w,h);
20         //cxt.strokeRect(200,200,100,100);
21         cxt.strokeRect(200.5,200.5,100,100);
22     </script>

【新知識點】:

  1、fillStyle    //填充的顏色

  2、strokeStyle   //邊框的顏色

  3、lineWidth  //線寬度

【注意】:(不然將不會運行)

  屬性,方法都用的駱駝命名法,首字母為小寫,第二個單詞首字母大寫;如userName。因為看上去像駝峰,因此而得名。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM