javascript
1<script>
2window.addEventListener('DOMContentLoaded', ()=>{
3 document.querySelector('#btn').addEventListener('click', ()=>{
4 const stroke_color="orange";
5 const text_color="black";
6 const base_color="gold";
7 const radian=180/Math.PI;
8 const cx=100;
9 const cy=100;
10 const r=80;
11 const S=-90;
12 let E=S;
13 let per=0;
14 const max_per=100;
15 const p1=document.querySelector('#p1');
16 const t1=[["x",cx],["y",cy]].reduce((x,y)=>(x.setAttribute(y[0],y[1]),x),document.querySelector('#t1'));
17 const speed1=2; // bigger is faster
18 const speed2=10; // smaller is faster
19 p1.setAttribute('stroke',stroke_color);
20 p2.setAttribute('fill',base_color);
21 t1.setAttribute('fill',text_color);
22 var timerId=setInterval(()=>{
23 E+=speed1;
24 per=Math.round((E-S)/360*100);
25 if(per>=max_per){
26 per=max_per;
27 E=per/100*360+S;
28 clearInterval(timerId);
29 }
30 if(per>=100){
31 E-=0.1;
32 }
33 let f1=(E-S)<=180?0:1;
34 let x1=cx+r*Math.cos(S/radian);
35 let y1=cy+r*Math.sin(S/radian);
36 let x2=cx+r*Math.cos(E/radian);
37 let y2=cy+r*Math.sin(E/radian);
38 let dx=x2-x1;
39 let dy=y2-y1;
40 let d1=`M ${x1},${y1} a ${r} ${r} ${S} ${f1} 1 ${dx},${dy} `;
41 let d2=d1+`L ${cx},${cy}`;
42 p2.setAttribute('d',d2);
43 p1.setAttribute('d',d1);
44 t1.textContent=per+"%";
45 },speed2);
46 });
47});
48</script>
49<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
50<circle cx="100" cy="100" r="80" fill="lightgray" stroke-width="10" stroke="gray" />
51<path id="p2" d="" fill="none" />
52<path id="p1" d="" fill="none" stroke-width="10" />
53<text id="t1" x="50%" y="50%" text-anchor="middle" dominant-baseline="central" fill="black" font-size="20px" >0%</text>
54</svg>
55<input type="button" value="btn" id="btn">
※ゴミがまざってたので削除