2017-01-11 179 views
2

如何使用CSS創建此圓形進度條甚至可能(兼容IE10 +,FF,鉻,Safari等)?
我想我們可以使用SVG,但我不知道如何做到這一點。圓形邊框進度條

在圓周圍有一個根據進度百分比動態變化的小邊框或陰影。如果百分比是100%,則邊框將完整地圍繞填充進度條的圓圈。

circle progress bar with a border to show progress

+0

你能請提供一些你的手試過的代碼? – Draval

回答

4

圈進度條是適用的形式這樣的回答:circular progress bar

它使用SVG與Snap.svg動畫計數器的藍色筆畫和JS:

Circle progress bar

var count = $(('#count')); 
 
$({ Counter: 0 }).animate({ Counter: count.text() }, { 
 
    duration: 5000, 
 
    easing: 'linear', 
 
    step: function() { 
 
    count.text(Math.ceil(this.Counter)+ "%"); 
 
    } 
 
}); 
 

 
var s = Snap('#animated'); 
 
var progress = s.select('#progress'); 
 

 
progress.attr({strokeDasharray: '0, 251.2'}); 
 
Snap.animate(0,251.2, function(value) { 
 
    progress.attr({ 'stroke-dasharray':value+',251.2'}); 
 
}, 5000);
body{text-align:center;font-family:sans-serif;background:#080808;} 
 
svg{width:30%;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/snap.svg/0.3.0/snap.svg-min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<svg id="animated" viewbox="0 0 100 100"> 
 
    <path id="progress" stroke-width="3" stroke="#4596AB" fill="none" 
 
     d="M50 10 
 
      a 40 40 0 0 1 0 80 
 
      a 40 40 0 0 1 0 -80"> 
 
    </path> 
 
    <circle cx="50" cy="50" r="38" fill="transparent" stroke="#fff" stroke-width="1"/> 
 
    <text id="count" x="50" y="50" fill="#fff" text-anchor="middle" dy="7" font-size="20">100%</text> 
 
</svg>

+0

太棒了!這很完美,就像我想要的一樣。非常感謝! – kazou