canvas環形資料效果
分享一段程式碼例項,它利用canvas實現了環形資料效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>螞蟻部落</title> <script> //適配 var html = document.getElementsByTagName("html")[0]; function getFontSize() { var width = document.documentElement.clientWidth || document.body.clientWidth + "px"; var fontSize = (100 / 750) * width; if (width >= 750) { fontSize = "100"; } return fontSize; } html.style.fontSize = getFontSize() + "px"; window.onresize = function () { setTimeout(function () { html.style.fontSize = getFontSize() + "px"; }, 100) }; window.onload = function () { var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); //已還金額/總金額 var rand = 3000 / 5000 * 100; var angle = 0; var rot = 360 - rand; function draw(angle) { ctx.save(); ctx.translate(75, 75); ctx.rotate(-Math.PI / 2) ctx.fillStyle = "#fce5cc"; ctx.beginPath(); ctx.arc(0, 0, 100, Math.PI / 180 * angle, Math.PI * 2, false); ctx.lineTo(0, 0); ctx.closePath(); ctx.fill(); ctx.restore(); } var timer = setInterval(function () { angle += 1; if (angle >= rot) { clearInterval(timer); } ctx.clearRect(0, 0, 150, 150); //相當於初始化 draw(angle); }, 5); } </script> <style> .Box { width: 100%; padding: .34rem 0; border-bottom: 1px solid #d7d7d7; background: #fff; } .Box .wradius { width: 2.52rem; height: 2.52rem; border-radius: 50%; background: #fce5cc; margin: 0 auto; position: relative; } .Box .nradius { width: 1.78rem; height: 1.78rem; border-radius: 50%; background: #3b3b3b; left: 50%; top: 50%; margin-top: -0.89rem; margin-left: -0.89rem; border: 2px solid #f27d00; position: absolute; text-align: center; } .Box p { font-size: .24rem; color: #fff; padding-top: .38rem; padding-bottom: .1rem; } .Box h1 { font-size: .48rem; color: #f27d00; } .Box .jiekxq { color: #f27d00; font-size: .28rem; position: relative; text-align: right; padding: 0 .3rem; display: block; } .Box .jiekxq img { position: absolute; right: 1.9rem; width: .3rem; top: .08rem; } .moneypice { padding: 0 .3rem; margin: .33rem 0 .2rem; border: 1px solid #d7d7d7; border-right: none; border-left: none; background: #fff; } .moneypice p { color: #161615; font-size: .32rem; border-bottom: 1px solid #d7d7d7; line-height: 1.1rem; overflow: hidden; } .moneypice p b { float: left; } .moneypice p span { color: #f27d00; text-align: center; float: left; width: 5rem; text-align: center; } .moneypice p img { float: right; width: .19rem; height: .3rem; margin-top: .4rem; } #canvas { background: #f27d00; border-radius: 50%; overflow: hidden; width: 2.52rem; height: 2.52rem; } </style> </head> <body> <div class="wrapper"> <div class="Box"> <div class="wradius"> <canvas id="canvas" width="150" height="150"></canvas> <div class="nradius"> <p>1111</p> <h1>5175</h1> </div> </div> </div> </div> </body> </html>
相關文章
- canvas環形進度條效果Canvas
- canvas環形百分比進度條效果Canvas
- canvas圓形時鐘效果Canvas
- canvas圓形隨機漂浮效果Canvas隨機
- canvas環形倒數計時Canvas
- canvas實現的圓形時鐘效果Canvas
- Canvas環形倒數計時元件Canvas元件
- canvas繪製圓形框效果不填充內部Canvas
- canvas實現的圓形走動鐘錶效果Canvas
- CSS3環形輻射效果CSSS3
- 快速生成一組環形資料
- 實現環形進度條效果【一】
- canvas實現的動態心形效果程式碼例項Canvas
- canvas實現的圓形鐘錶效果程式碼例項Canvas
- CSS 線條環形動態運動效果CSS
- 滑鼠懸浮實現環形旋轉效果
- Canvas圖形編輯器-資料結構與History(undo/redo)Canvas資料結構
- canvas百分比環形進度條程式碼Canvas
- jQuery環形旋轉載入進度條效果jQuery
- canvas小球碰壁效果Canvas
- canvas矩形拖拽效果Canvas
- canvas簽名效果Canvas
- canvas 繪製圓形Canvas
- canvas繪製流星效果Canvas
- canvas實現波浪效果Canvas
- canvas小球擺動效果Canvas
- canvas蔚藍星空效果Canvas
- 用初中數學知識擼一個canvas環形進度條Canvas
- canvas圖形編輯器Canvas
- 畫影圖形: SVG & Canvas 圖形對比SVGCanvas
- canvas設定陰影效果Canvas
- canvas繪製風車效果Canvas
- canvas小球落地彈動效果Canvas
- canvas簡單畫板效果Canvas
- canvas畫布效果程式碼Canvas
- canvas動態時鐘效果Canvas
- canvas立體效果的圓環Canvas
- canvas卡通形象笑臉效果Canvas