您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關(guān)canvas如何實現(xiàn)簡易的圓環(huán)進度條效果,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
效果圖:
代碼如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <style type="text/css"> canvas{ border: 1px solid #1F232A; } .div{ width: 400px; height: 50px; } input,button{ text-align: center; font-size: 20px; } </style> <body> <canvas id="main" width="450" height="300"></canvas> <div class="div"> 進度:<input id="num" type="number" value="100" max="100"/> <button id="makeSure">確定</button> </div> </body> <script type="text/javascript"> var makeSure=document.getElementById("makeSure"); makeSure.onclick=function(){ var ctx=document.getElementById("main").getContext("2d"); ctx.clearRect(0,0,450,300); var num=parseInt(document.getElementById("num").value)+1; if(num<=101){ for (var x=0;x<num;x++) { (function(x){ setTimeout(function(){ ctx.beginPath() ctx.lineWidth=10; ctx.strokeStyle='orange'; ctx.arc(200, 200, 50, -90 * Math.PI / 180, (x * 3.6 - 90) * Math.PI / 180); ctx.stroke(); ctx.clearRect(390,25,50,50); ctx.clearRect(175,175,55,55) ctx.fillStyle = 'orange'; ctx.fillRect(10+x*3.5,30,3.5,40); ctx.font="20px Arial"; ctx.fillText(x+"%",390,58) ctx.fillText(x+"%",175,208) },x*30); })(x); } }else{ alert("請輸入0-100之間的數(shù)字") } } makeSure.click(); </script> </html>
關(guān)于“canvas如何實現(xiàn)簡易的圓環(huán)進度條效果”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。