canvas繪製圓角矩形程式碼例項
分享一段簡單的程式碼例項,它實現了繪製圓角矩形的功能。
非常適合初學者瞭解相關方法和屬性的使用,程式碼例項如下:
[HTML] 純文字檢視 複製程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <style> * { padding: 0; margin: 0; } </style> </head> <body bgcolor="#00aeff"> <script type="text/javascript"> var canvas = document.createElement("canvas"); var canW = canH = 600; canvas.width = canW; canvas.height = canH; document.body.appendChild(canvas); var ctx = canvas.getContext("2d"); var w = h = 300; //矩形的寬高 var x = canW/2 - w/2; //開始的x軸座標 var y = canH/2 - h/2; //開始的y軸座標 var r = 15; //圓角半徑 var bdWidth = 8; //邊框寬度 var bdColor = "f00000"; //邊框的顏色 var bgcolor = "#ffffff"; //矩形背景的顏色 drawRoundedRect(x,y,w,h,r,bdWidth,bdColor,bgcolor); function drawRoundedRect(x,y,w,h,r,bdWidth,bdColor,bgcolor){ ctx.beginPath(); ctx.moveTo(x+r,y); ctx.lineWidth = bdWidth; ctx.strokeStyle = bdColor; ctx.fillStyle = bgcolor; ctx.arcTo(x+w,y,x+w,y+h,r); ctx.arcTo(x+w,y+h,x,y+h,r); ctx.arcTo(x,y+h,x,y,r); ctx.arcTo(x,y,x+w,y,r); ctx.stroke(); ctx.fill(); ctx.closePath(); } </script> </body> </html>
相關文章
- canvas 繪製圓角矩形Canvas
- 微信小程式 canvas圓角矩形的繪製微信小程式Canvas
- canvas繪製圓形鐘錶程式碼例項Canvas
- canvas 繪製矩形缺角Canvas
- SVG 繪製圓角矩形SVG
- 原來 Canvas 也能直接繪製圓角矩形了Canvas
- canvas繪製扇形程式碼例項Canvas
- SVG拖動繪製矩形程式碼例項SVG
- canvas繪製網格程式碼例項Canvas
- css繪製圓形程式碼例項CSS
- canvas繪製機器貓程式碼例項Canvas
- canvas繪製拋物線程式碼例項Canvas線程
- canvas繪製箭頭效果程式碼例項Canvas
- canvas 繪製矩形Canvas
- iOS開發_繪製圓角矩形虛線環iOS
- canvas繪製矩形框Canvas
- canvas系列教程之繪製矩形Canvas
- canvas 繪製圓形Canvas
- iOS 繪製圓角iOS
- canvas實現手動繪製矩形Canvas
- canvas-座標系、圓角矩形、紋理、剪裁Canvas
- canvas繪製不重合的圓Canvas
- canvas 繪製立體圓環Canvas
- CSS繪製橢圓程式碼CSS
- 使用canvas繪製圓弧動畫Canvas動畫
- canvas繪製多個圓圈效果Canvas
- visio圓角矩形怎麼改變圓角大小
- css圓角矩形邊框CSS
- canvas刮刮樂程式碼例項Canvas
- canvas載入效果程式碼例項Canvas
- Canvas 繪製 3d 圓柱體Canvas3D
- 使用canvas繪製圓形進度條Canvas
- canvas學習筆記-繪製矩形及路徑(一)Canvas筆記
- CSS橢圓效果程式碼例項CSS
- Python 在PDF中繪製線條、矩形、橢圓形Python
- canvas原型鐘錶效果程式碼例項Canvas原型
- canvas氣泡上浮效果程式碼例項Canvas
- canvas繪製圓盤走動鐘錶效果Canvas
- CSS3繪製太極圖程式碼例項詳解CSSS3