JSFiddle - React, Tailwind, and code Playground
HTML
<div id="temperature-gauge" class="gauge-control" data-percentage="0">
<div class="header">Temperature</div>
<div class="gauge-elements">
<div class="gauge">
<div class="inner"></div>
<div class="spinner temp"></div>
</div>
<div class="pointer"></div>
<div class="pointer-knob"></div>
</div>
<div class="indicator">60° C</div>
</div>
CSS
body {
font-family: sans-serif;
background-color: #2a2a2a;
color: #ccc;
}
.gauges {
text-align: center;
}
.gauge-control {
text-align: center;
display: inline-block;
position: relative;
width: 200px;
margin: 20px;
}
.gauge-control:first-child {
margin: 0;
}
.gauge-control > .header {
margin-bottom: 20px;
font-size: 30px;
}
.gauge-control > .gauge-elements {
position: relative;
height: 100px;
}
.gauge-control .indicator {
font-size: 30px;
margin-top: 20px;
}
.gauge-control .pointer {
display: block;
width: 6px;
height: 105px;
background-color: #fff;
border-radius: 4px 4px 0 0;
position: absolute;
z-index: 4;
bottom: 0;
left: 97px;
transform: rotate(-90deg);
transform-origin: center bottom;
transition: transform 1s ease;
}
.gauge-control .pointer-knob {
width: 20px;
height: 20px;
background-color: #fff;
position: absolute;
left: 90px;
bottom: -10px;
z-index: 5;
border-radius: 20px;
}
.gauge {
width: 200px;
height: 100px;
position: relative;
overflow: hidden;
}
.gauge > .inner {
width: 200px;
height: 100px;
display: block;
background-color: #444444;
border-radius: 200px 200px 0 0;
z-index: 1;
}
.gauge > .inner:after {
content: '';
width: 120px;
height: 60px;
top: 40px;
left: 40px;
background-color: #2a2a2a;
border-radius: 200px 200px 0 0;
position: absolute;
z-index: 3;
}
.gauge > .spinner {
width: 200px;
height: 100px;
background-color: #d44646;
position: absolute;
z-index: 2;
transform-origin: top center;
transform: rotate(0deg);
transition: transform 1s ease;
transform: translateZ(0);
border-radius: 0 0 200px 200px;
}
JavaScript
function setGauge(gauge, indicatorHtml, newPercentage)
{
if (typeof(indicatorHtml) !== 'undefined' && indicatorHtml != null) {
$(gauge).find('> .indicator').html(indicatorHtml);
}
if (typeof(newPercentage)!== 'undefined' && newPercentage != null) {
$(gauge).data('percentage', newPercentage)
}
var percentage = $(gauge).data('percentage') / 100;
var degrees = 180 * percentage;
var pointerDegrees = degrees - 90;
var spinner = $(gauge).find('.spinner');
var pointer = $(gauge).find('.pointer');
$(spinner).attr({
style: 'transform: rotate(' + degrees + 'deg)'
});
$(pointer).attr({
style: 'transform: rotate(' + pointerDegrees + 'deg)'
});
}
setGauge($("#temperature-gauge"), '60° C', 74);