久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      詳解canvas實(shí)現(xiàn)圓弧、圓環(huán)進(jìn)度條的實(shí)例方法

      下面總結(jié)了自己在項(xiàng)目中的圓形進(jìn)度條效果的實(shí)現(xiàn)方式,希望對(duì)大家有幫助:

      此方法通過canvas繪制圓形的方法來實(shí)現(xiàn)動(dòng)態(tài)圓環(huán)進(jìn)度條,直接上代碼,疑問請(qǐng)看注釋:

      HTML代碼如下, 在頁面里創(chuàng)建一個(gè)畫布即可:

      <canvas id="canvas" width="300" height="300">      <p>抱歉,您的瀏覽器不支持canvas</p>   </canvas>

      JS分兩大部分,
      第一部分實(shí)現(xiàn)整體功能,第二部分調(diào)用:
      第一部分:
        第一部分功能原理大概是,畫兩個(gè)圓,一個(gè)是底色圓,第二個(gè)是動(dòng)態(tài)加載的圓弧,進(jìn)度通過定時(shí)器加載;顏色加漸變色;

       function toCanvas(id ,progress){                canvas進(jìn)度條                  var canvas = document.getElementById(id),                  ctx = canvas.getContext("2d"),                  percent = progress,  最終百分比                circleX = canvas.width / 2,  中心x坐標(biāo)                circleY = canvas.height / 2,  中心y坐標(biāo)                radius = 100, 圓環(huán)半徑                lineWidth = 5,  圓形線條的寬度                fontSize = 20; 字體大小                   兩端圓點(diǎn)                  function smallcircle1(cx, cy, r) {                      ctx.beginPath();                    //ctx.moveTo(cx + r, cy);                    ctx.lineWidth = 1;                      ctx.fillStyle = '#06a8f3';                      ctx.arc(cx, cy, r,0,Math.PI*2);                      ctx.fill();                  }                 function smallcircle2(cx, cy, r) {                       ctx.beginPath();                     //ctx.moveTo(cx + r, cy);                     ctx.lineWidth = 1;                       ctx.fillStyle = '#00f8bb';                       ctx.arc(cx, cy, r,0,Math.PI*2);                       ctx.fill();                   }                 畫圓                   function circle(cx, cy, r) {                       ctx.beginPath();                     //ctx.moveTo(cx + r, cy);                     ctx.lineWidth = lineWidth;                       ctx.strokeStyle = '#eee';                       ctx.arc(cx, cy, r, Math.PI*2/3, Math.PI * 1/3);                       ctx.stroke();                   }                 畫弧線                   function sector(cx, cy, r, startAngle, endAngle, anti) {                       ctx.beginPath();                     //ctx.moveTo(cx, cy + r); // 從圓形底部開始畫                     ctx.lineWidth = lineWidth;                     // 漸變色 - 可自定義                       var linGrad = ctx.createLinearGradient(                           circleX-radius-lineWidth, circleY, circleX+radius+lineWidth, circleY                       );                       linGrad.addColorStop(0.0, '#06a8f3');                     //linGrad.addColorStop(0.5, '#9bc4eb');                     linGrad.addColorStop(1.0, '#00f8bb');                       ctx.strokeStyle = linGrad;                      圓弧兩端的樣式                     ctx.lineCap = 'round';                     圓弧                     ctx.arc(                           cx, cy, r,                           (Math.PI*2/3),                         (Math.PI*2/3) + endAngle/100 * (Math.PI*5/3),                           false                       );                       ctx.stroke();                   }                  刷新                   function loading() {                     if (process >= percent) {                           clearInterval(circleLoading);                       }                      清除canvas內(nèi)容                     ctx.clearRect(0, 0, circleX * 2, circleY * 2);                    中間的字                     ctx.font = fontSize + 'px April';                       ctx.textAlign = 'center';                       ctx.textBaseline = 'middle';                       ctx.fillStyle = '#999';                       ctx.fillText(parseFloat(process).toFixed(0) + '%', circleX, circleY);                                               圓形                     circle(circleX, circleY, radius);                                             圓弧                     sector(circleX, circleY, radius, Math.PI*2/3, process);                       兩端圓點(diǎn)                     smallcircle1(150+Math.cos(2*Math.PI/360*120)*100, 150+Math.sin(2*Math.PI/360*120)*100, 5);                       smallcircle2(150+Math.cos(2*Math.PI/360*(120+process*3))*100, 150+Math.sin(2*Math.PI/360*(120+process*3))*100, 5);                     控制結(jié)束時(shí)動(dòng)畫的速度                       if (process / percent > 0.90) {                           process += 0.30;                       } else if (process / percent > 0.80) {                           process += 0.55;                       } else if (process / percent > 0.70) {                           process += 0.75;                       } else {                           process += 1.0;                       }                   }                 var process = 0.0;  進(jìn)度                   var circleLoading = window.setInterval(function () {                       loading();                   }, 20);                                     }  第二部分,調(diào)用封裝好的代碼:              toCanvas('canvas',50);

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)