canvas環形百分比進度條效果
分享一段程式碼例項,它利用canvas實現了百分比環形進度條效果。
程式碼例項如下:
[HTML] 純文字檢視 複製程式碼執行程式碼<!doctype html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.softwhy.com/" /> <title>螞蟻部落</title> <script> window.onload = function() { window.onload = function() { var canvas = document.getElementById("canvas"); context = canvas.getContext('2d'); centerX = canvas.width / 2; centerY = canvas.height / 2; rad = Math.PI * 2 / 100; speed = 0.1; function blueCircle(n) { context.save(); context.strokeStyle = "#49f"; context.lineWidth = 5; context.beginPath(); context.arc(centerX, centerY, 100, -Math.PI / 2, -Math.PI / 2 + n * rad, false); context.stroke(); context.closePath(); context.restore(); } function whiteCircle() { context.save(); context.strokeStyle = "white"; context.beginPath(); context.arc(centerX, centerY, 100, 0, Math.PI * 2, false); context.stroke(); context.closePath(); context.restore(); } function text(n) { context.save(); context.strokeStyle = "#49f"; context.font = "40px Arial"; context.strokeText(n.toFixed(0) + "%", centerX - 25, centerY + 10); context.stroke(); context.restore(); } (function drawFrame() { window.requestAnimationFrame(drawFrame, canvas); context.clearRect(0, 0, canvas.width, canvas.height); whiteCircle(); text(speed); blueCircle(speed); if (speed > 100) speed = 0; speed += 0.1; }()); } var canvas = document.getElementById("canvas"); context = canvas.getContext('2d'); centerX = canvas.width / 2; centerY = canvas.height / 2; rad = Math.PI * 2 / 100; speed = 0.1; function blueCircle(n) { context.save(); context.strokeStyle = "#49f"; context.lineWidth = 5; context.beginPath(); context.arc(centerX, centerY, 100, -Math.PI / 2, -Math.PI / 2 + n * rad, false); context.stroke(); context.closePath(); context.restore(); } function whiteCircle() { context.save(); context.strokeStyle = "white"; context.beginPath(); context.arc(centerX, centerY, 100, 0, Math.PI * 2, false); context.stroke(); context.closePath(); context.restore(); } function text(n) { context.save(); context.strokeStyle = "#49f"; context.font = "40px Arial"; context.strokeText(n.toFixed(0) + "%", centerX - 25, centerY + 10); context.stroke(); context.restore(); } (function drawFrame() { window.requestAnimationFrame(drawFrame, canvas); context.clearRect(0, 0, canvas.width, canvas.height); whiteCircle(); text(speed); blueCircle(speed); if (speed > 100) speed = 0; speed += 0.1; }()); } </script> </head> <body> <canvas id="canvas" width="500" height="500" style="background:#000"></canvas> </body> </html>
相關文章
- canvas環形進度條效果Canvas
- canvas百分比環形進度條程式碼Canvas
- 實現環形進度條效果【一】
- jQuery環形旋轉載入進度條效果jQuery
- canvas錐形漸變進度條Canvas
- 使用canvas繪製圓形進度條Canvas
- 用初中數學知識擼一個canvas環形進度條Canvas
- CSS3圓形進度條效果CSSS3
- Android花樣loading進度條(三)-配文字環形進度條Android
- canvas 畫進度條Canvas
- Vue canvas繪製圓形進度條動畫載入VueCanvas動畫
- Js 百分比進度條JS
- 直播商城系統原始碼,環形進度條元件原始碼元件
- YCProgress自定義百分比進度條
- JavaScript百分比動態進度條JavaScript
- svg和css3建立環形漸變進度條SVGCSSS3
- 直播電商平臺開發,環形進度條元件元件
- Flutter 波浪圓形進度條Flutter
- 前端學習筆記:使用canvas繪製有圓角的百分比進度條前端筆記Canvas
- CSS 線條環形動態運動效果CSS
- canvas圓形時鐘效果Canvas
- Android自定義圓形進度條Android
- jQuery實進度條效果詳解jQuery
- 短視訊商城系統,Android進度條,自定義進度條,顯示百分比Android
- 一對一聊天原始碼,vue實現環形進度條元件原始碼Vue元件
- vue 自定義指令實現,滾動條百分比進度條。Vue
- [-Flutter 自定義元件-] 圓形進度條Flutter元件
- 直播網站原始碼,Canvas實現圓形時間倒數計時進度條網站原始碼Canvas
- JavaScript 動態進度條效果詳解JavaScript
- iOS實現音訊進度條效果iOS音訊
- CSS3進度條效果程式碼CSSS3
- Android 自定義圓形旋轉進度條,仿微博頭像載入效果Android
- Flutter實現圓形波浪進度球【canvas+animation】FlutterCanvas
- ios自定義圓環進度條iOS
- 自定義圓形進度條控制元件控制元件
- CSS3實現原型進度條效果CSSS3原型
- 【新特性速遞】進度條,進度條,進度條
- 直播平臺搭建原始碼,canvas 畫一條波浪線 進度條原始碼Canvas
- (精華)2020年6月28日 Canvas 進度條Canvas