html5 canvas(基本矩形),html5canvas矩形

來源:互聯網
上載者:User

html5 canvas(基本矩形),html5canvas矩形

先從簡單的開始

fillRect(x,y,width,height)

 在座標x,y的位置加上一個寬,高   如:

fillRect(0,0,500,500)//在座標0,0處加上一個寬高500的填充矩形

 

strokeRect(x,y,width,height)

  在座標x,y的位置加上一個寬,高邊框矩形

但是需要使用lineWidth,lineJoin,strokeStyle,miterLimit設定下面會給出矩形函數

clearRect(x,y,width,height)

 清除座標x,y的位置寬,高的一塊地區是起完全透明

感覺有點像用ps時候一個黑色的圖層,拉一個矩形選框,然後按個delect的感覺一塊透明

 

然後設定一下填充樣式

context.fillStyle='#000000'    //填充顏色context.strokeStyle='#ff00ff'    //邊框顏色

 

完整代碼

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>矩形</title><script src="js/modernizr.js"></script></head><body><script type="text/javascript">window.addEventListener('load',eventWindowLoaded,false);function eventWindowLoaded(){canvasApp();}function canvasSupport(){return Modernizr.canvas;}function canvasApp(){if(!canvasSupport()){return;}else{var theCanvas = document.getElementById('canvas')var context = theCanvas.getContext("2d")}drawScreen();    function drawScreen(){context.fillStyle="#000000";   //填充黑色context.strokeStyle='#ff00ff'     //邊框為粉色context.lineWidth=2;              //邊框寬度        context.fillRect(10,10,40,40)     //矩形        context.strokeRect(0,0,60,60)    //邊框出現的位置        context.clearRect(20,20,20,20)   //清除地區的位置}}</script><canvas id="canvas" width="500" height="500">你的瀏覽器無法使用canvas如有疑問加QQ:1035417613;小白童鞋;你的支援是我最大的快樂!!</canvas></body></html>

 

結果就是這樣一個

如果對前面的結構不瞭解的話可以看我的上一篇http://www.cnblogs.com/LoveOrHate/p/4388321.html

 

聯繫我們

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