svg實現圓環進度條


開源實現:https://github.com/lugolabs/circles

自行實現:圓環與svg畫布間剩的空間太多。

    
<!DOCTYPE html>
<html> 
<head> 
<meta charset=" utf-8"> 
<title>圓環進度條</title> 
<style type="text/css">
circle{
  -webkit-transition: stroke-dasharray .25s;
  transition: stroke-dasharray .25s;
}
</style>
<script>
window.onload = function () {
  if (window.addEventListener) {
    var range = document.querySelector("#range");
    var circle = document.querySelectorAll("circle")[1];
    if (range && circle) {
      range.addEventListener("change", function () {
        console.log(this.value,2*Math.PI*50);
        var percent = this.value / 100, lineLength = 2*Math.PI * 50;
        circle.setAttribute('stroke-dasharray', lineLength* percent + " " + lineLength * (1 - percent));
      });
    }
  }
}
</script>
</head>
<body>
<svg width="200" height="200">
  <circle cx="100" cy="100" r="50" stroke-width="10" stroke="#D1D3D7" fill="none"></circle>
  <circle cx="100" cy="100" r="50" stroke-width="10" stroke="#00A5E0" fill="none"  stroke-dasharray="0 50">
  </circle>
</svg>
<p>拖我:<input id="range" type="range" min="0" max="100" value="0" style="width:300px;"></p>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM