canvas環形進度條效果
分享一段程式碼例項,它實現了環形進度條效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script type="text/javascript"> window.onload = function() { var canvas = document.getElementById("canvas"); var ctx = canvas.getContext("2d"); var W = canvas.width; var H = canvas.height; var degrees = 0; var new_degrees = 0; var difference = 0; var color = "green"; var bgcolor = "#E8E8E8"; var text; var animation_loop, redraw_loop; function init() { ctx.clearRect(0, 0, W, H); ctx.beginPath(); ctx.strokeStyle = bgcolor; ctx.lineWidth = 10; ctx.arc(W / 2, H / 2, 100, 0, Math.PI * 2, false); //you can see the arc now ctx.stroke(); var radians = degrees * Math.PI / 180; ctx.beginPath(); ctx.strokeStyle = color; ctx.lineWidth = 10; ctx.arc(W / 2, H / 2, 100, 0 - 90 * Math.PI / 180, radians - 90 * Math.PI / 180, false); ctx.stroke(); ctx.fillStyle = color; ctx.font = "20px bebas"; text = Math.floor(degrees / 360 * 100) + "%"; text_width = ctx.measureText(text).width; ctx.fillText(text, W / 2 - text_width / 2, H / 2 + 15); } function draw() { if (typeof animation_loop != undefined) clearInterval(animation_loop); new_degrees = new_degrees + 1; difference = new_degrees - degrees; animate_to(); } function animate_to() { if (degrees == new_degrees) clearInterval(animation_loop); if (degrees == 360) return; if (degrees < new_degrees) { degrees++; } else { degrees--; } init(); } draw(); redraw_loop = setInterval(draw, 10); } </script> </head> <body> <canvas id="canvas" width="250" height="250"></canvas> </body> </html>
相關文章
- canvas環形百分比進度條效果Canvas
- 實現環形進度條效果【一】
- jQuery環形旋轉載入進度條效果jQuery
- canvas錐形漸變進度條Canvas
- canvas百分比環形進度條程式碼Canvas
- 使用canvas繪製圓形進度條Canvas
- canvas的簡單圓形進度條Canvas
- 用初中數學知識擼一個canvas環形進度條Canvas
- canvas圓形進度條註釋超全Canvas
- CSS3圓形進度條效果CSSS3
- canvas環形資料效果Canvas
- canvas 畫進度條Canvas
- canvas實現具有粒子效果的動態進度條Canvas
- Android花樣loading進度條(三)-配文字環形進度條Android
- svg環形百分比進度條SVG
- 直播電商平臺開發,環形進度條元件元件
- 直播商城系統原始碼,環形進度條元件原始碼元件
- svg和css3建立環形漸變進度條SVGCSSS3
- Flutter 波浪圓形進度條Flutter
- 自定義圓形進度條
- SVG畫圓形進度條SVG
- jQuery 進度條效果程式碼jQuery
- CSS快遞進度條效果CSS
- canvas水位進度效果程式碼例項Canvas
- CSS 線條環形動態運動效果CSS
- jQuery實進度條效果詳解jQuery
- 一對一聊天原始碼,vue實現環形進度條元件原始碼Vue元件
- canvas圓形時鐘效果Canvas
- [-Flutter 自定義元件-] 圓形進度條Flutter元件
- Android自定義圓形進度條Android
- 直播網站原始碼,Canvas實現圓形時間倒數計時進度條網站原始碼Canvas
- JavaScript 動態進度條效果詳解JavaScript
- iOS實現音訊進度條效果iOS音訊
- jQuery進度條效果程式碼例項jQuery
- CSS3進度條效果程式碼CSSS3
- 【新特性速遞】進度條,進度條,進度條
- Android 自定義圓形旋轉進度條,仿微博頭像載入效果Android
- Flutter實現圓形波浪進度球【canvas+animation】FlutterCanvas