//======== CONFIGURATION WINDOW
//======== i made this configuration code here you can change value and experiment
var x = 200;//set the x - center here
var y = 200;//set the y - center here
var r = 50;//set the radius here
var linewidth=50;//set the line width here
var SET_COLOR="#00FFFF";//set the color here
var SET_PERCENTAGE = 85 //set the percentage here
//========
var loaded = false;
window.onload = function() {
var status=document.getElementById('status');
status.style.top=y+'px';
status.style.left=x+'px';
loaded = true;
}
var ROTATION = 0;
function setcanvas() {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.translate(x,y);
ctx.rotate((Math.PI/180)*(-ROTATION));
ctx.translate(-x,-y);
ctx.clearRect(0,0,c.width,c.height);
ctx.beginPath();
ctx.lineWidth = 2;
ctx.strokeStyle="black";
ctx.arc(x,y,r+(linewidth/2),0,2*Math.PI);
ctx.globalAlpha=0.1;
ctx.stroke();
ctx.beginPath();
ctx.lineWidth = 2;
ctx.strokeStyle="black";
ctx.arc(x,y,r-(linewidth/2),0,2*Math.PI);
ctx.stroke();
}
function getPoint(c1,c2,radius,angle) {
return [c1+Math.cos(angle)*radius,c2+Math.sin(angle)*radius];
}
function setPercent(uplimit) {
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.beginPath();
ctx.translate(x,y);
ROTATION=270;
ctx.rotate((Math.PI/180)*ROTATION);
ctx.translate(-x,-y);
ctx.lineWidth = linewidth;//40
ctx.strokeStyle=SET_COLOR;
ctx.arc(x,y,r,(Math.PI/180)*(uplimit),0);
ctx.globalAlpha=1;
ctx.stroke();
ctx.beginPath();
var a = getPoint(x,y,r,(Math.PI/180)*(uplimit))[0];
var b = getPoint(x,y,r,(Math.PI/180)*(uplimit))[1];
nr = linewidth/2;
ctx.lineWidth = 1;
ctx.strokeStyle="white";
ctx.arc(a,b,nr,0,2*Math.PI);
ctx.fillStyle="white";
ctx.fill();
ctx.stroke();
ctx.beginPath();
var a = getPoint(x,y,r,(Math.PI/180)*(uplimit))[0];
var b = getPoint(x,y,r,(Math.PI/180)*(uplimit))[1];
nr = linewidth/2-3;
ctx.lineWidth = 1;
ctx.strokeStyle="white";
ctx.arc(a,b,nr,0,2*Math.PI);
ctx.fillStyle=SET_COLOR;
ctx.fill();
ctx.stroke();
}
function callcanvas(degree) {
setcanvas();
setPercent(360-degree);
}
var degree = parseInt((SET_PERCENTAGE*360)/100);
var start = 0;
var it = window.setInterval(function(){
callcanvas(start);
start++;
if(start == degree) {
start = 0;
window.setInterval(it);
}
if(loaded)
document.getElementById("status").innerHTML = parseInt((start*100)/360)+'%';
},1);
<div style='position:absolute;top:0px;left:0px;' id='status'>
0%
</div>
<canvas id="myCanvas" width="400" height="400" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
即使不需要jQuery的,只有一個簡單的JavaScript更好。等待更多的信息,非常感謝 – Ryuka 2014-12-14 06:23:47
代碼發佈在下面,你只需要設置javascript代碼的程度,你可以在我的網站上查看輸出http://vitideas.in/web/ :-) – 2014-12-14 18:21:16
真棒,謝謝你的幫助。 我還有一些問題。 1.有沒有辦法用漸變代替顏色?我試着用ctx.createLinearGradient,但似乎不工作(導致一個純色)2.有沒有辦法讓酒吧從左側走向右側3.如何讓腳本只運行一次? 4.有沒有加快動畫的方法? – Ryuka 2014-12-15 06:47:03