-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.html
100 lines (93 loc) · 3.16 KB
/
score.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Circular Score Tracker</title>
<style>
body {
display: flex;
justify-content: center;
align-items: center;
/* height: 100vh; */
margin: 0;
font-family: Arial, sans-serif;
background-color: #f0f0f0;
}
.score-tracker {
position: relative;
width: 250px;
height: 250px;
}
#backgroundCircle {
fill: none;
stroke: #e0e0e0;
stroke-width: 20;
}
#progressCircle {
fill: none;
stroke-width: 20;
transform: rotate(-90deg);
transform-origin: center;
transition: stroke 0.5s ease;
}
#scoreText {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 36px;
font-weight: bold;
}
#slider {
width: 250px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h3>Desktop best practices</h3>
<div class="score-tracker" >
<svg width="250" height="250" >
<circle id="backgroundCircle" cx="125" cy="125" r="105" />
<circle id="progressCircle" cx="125" cy="125" r="105"/>
</svg>
<div id="scoreText">0</div>
</div>
<!-- <input type="range" id="slider" min="0" max="100" value="0"> -->
</div>
<script>
const progressCircle = document.getElementById('progressCircle');
const scoreText = document.getElementById('scoreText');
const slider = document.getElementById('slider');
function updateScore(score) {
// Calculate circle circumference
const radius = 105;
const circumference = 2 * Math.PI * radius;
// Update progress circle
const progress = circumference * (1 - score / 100);
progressCircle.style.strokeDasharray = `${circumference}`;
progressCircle.style.strokeDashoffset = progress;
// Set color based on score
if (score <= 33) {
progressCircle.style.stroke = '#ff4136'; // Red
progressCircle.style.backgroundColor = '#ffcccc'; // Light red
} else if (score <= 66) {
progressCircle.style.stroke = '#ffdc00'; // Yellow
progressCircle.style.backgroundColor = '#ffffcc'; // Light yellow
} else {
progressCircle.style.stroke = '#2ecc40'; // Green
progressCircle.style.backgroundColor = '#ccffcc'; // Light green
}
// Update score text
scoreText.textContent = Math.round(score);
}
// Initial setup
updateScore(93);
// Slider event listener
slider.addEventListener('input', (e) => {
updateScore(e.target.value);
});
</script>
</body>
</html>