2013-10-29 238 views
-1

這樣的百分比曲線怎樣才能讓使用CSS3我怎樣才能讓使用CSS3

+1

你應該嘗試的東西你要的代碼之前。此外,請告訴我們您嘗試了什麼,您的期望以及發生了什麼,以及您使用的代碼。 – usernolongerregistered

+0

你究竟是什麼意思?請提供更多細節和/或迄今爲止嘗試的內容。 http://stackoverflow.com/help/how-to-ask可能會有幫助:) –

+0

CSS是這個錯誤的工具。改用SVG。 – Spudley

回答

0

看到這個link

HTML

<div class="container"> 
<div id="percent"></div> 
<svg id="svg"></svg> 
<p><label for="perc-input">Percent:</label><input maxlength="2" type="text" id="input" value="65"/></p> 
<a class="btn" id="run">Run</a> 
</div> 

CSS

這樣的比例曲線
@import url(http://fonts.googleapis.com/css?family=Share+Tech); 
body { 
background: #efefef; 
} 

.container { 
width: 400px; 
height: 200px; 
position: relative; 
margin: auto; 
font-family: 'Share Tech', sans-serif; 
color: #444; 
} 

#percent, #svg { 
width: 200px; 
height: 200px; 
position: absolute; 
top: 0; 
left: 0; 
} 

#percent { 
line-height: 20px; 
height: 20px; 
width 100%; 
top: 90px; 
font-size: 43px; 
text-align: center; 
color: #3da08d; 
opacity: 0.8 
} 

p, .btn { 
position: relative; 
left: 220px; 
width: 200px; 
display: block; 
text-transform: uppercase; 
font-size: 24px; 
top: 30px; 
} 

.btn { 
text-align: center; 
background: #5fc2af; 
color: #fff; 
width: 120px; 
height: 37px; 
line-height: 37px; 
cursor: pointer; 
} 

input { 
border: 0; 
outline: 0; 
border-bottom: 1px solid #eee; 
width: 30px; 
font-family: helvetica; 
font-size: 24px; 
text-transform: capitalise; 
font-family: 'Share Tech', sans-serif; 
background: transparent; 
} 

JS

var canvasSize = 200, 
centre = canvasSize/2, 
radius = canvasSize*0.8/2, 
s = Snap('#svg'), 
path = "", 
arc = s.path(path),  
startY = centre-radius, 
runBtn = document.getElementById('run'), 
percDiv = document.getElementById('percent'), 
input = document.getElementById('input'); 

input.onkeyup = function(evt) { 
if(isNaN(input.value)) { 
    input.value = ''; 
} 
}; 

runBtn.onclick = function() { 
run(input.value/100); 
}; 

function run(percent) { 
var endpoint = percent*360; 
Snap.animate(0, endpoint, function (val) { 
    arc.remove(); 

    var d = val, 
     dr = d-90; 
     radians = Math.PI*(dr)/180, 
     endx = centre + radius*Math.cos(radians), 
     endy = centre + radius * Math.sin(radians), 
     largeArc = d>180 ? 1 : 0; 
     path = "M"+centre+","+startY+" A"+radius+","+radius+" 0 "+largeArc+",1 "+endx+","+endy; 

    arc = s.path(path); 
    arc.attr({ 
     stroke: '#3da08d', 
     fill: 'none', 
     strokeWidth: 12 
    }); 
    percDiv.innerHTML = Math.round(val/360*100) +'%'; 

}, 2000, mina.easeinout); 
} 

run(input.value/100); 

通過rachstock

+0

「using CSS3」... – Ruddy

+0

CSS3是這個錯誤的工具 –

+0

然而,這是可能的,我的意思是你的權利,他們不應該只爲此使用CSS3。但這是可以完成的。 – Ruddy