溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

canvas如何實現(xiàn)簡易的圓環(huán)進度條效果

發(fā)布時間:2021-05-12 13:48:27 來源:億速云 閱讀:199 作者:小新 欄目:web開發(fā)

這篇文章將為大家詳細講解有關(guān)canvas如何實現(xiàn)簡易的圓環(huá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)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(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)容。

AI