Código de CSS - Indicador de mínimo y máximo con aguja que cambia de color

Imágen de perfil
Val: 870
Oro
Ha mantenido su posición en CSS (en relación al último mes)
Gráfica de CSS

Indicador de mínimo y máximo con aguja que cambia de colorgráfica de visualizaciones


CSS

Publicado el 21 de Septiembre del 2019 por Joel (150 códigos)
3.802 visualizaciones desde el 21 de Septiembre del 2019
Aquí les muestro una manera de crear un indicador con mínimo y máximo utilizando únicamente CSS para crear el dibujo.
A diferencia del código: https://www.lawebdelprogramador.com/codigo/CSS/5543-Indicador-de-minimo-y-maximo-con-aguja.html, en este la aguja va cambiando de color de verde a rojo según su valor.
Se puede utilizar con % o un valor mínimo y máximo.

minimo-y-maximo-con-aguja


Se utiliza javascript para mover los grados de la aguja, la cual se gira con CSS utilizando transform:rotate().

1
estrellaestrellaestrellaestrellaestrella(2)

Publicado el 21 de Septiembre del 2019gráfica de visualizaciones de la versión: 1
3.803 visualizaciones desde el 21 de Septiembre del 2019
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
 
    <style>
    .wrapper {
        text-align:center;
        width:300px;
        height:200px;
        position:relative;
    }
    .wrapper>div:first-child {
        border:1px solid #ababab;
        position:relative;
        height:150px;
        overflow:hidden;
    }
    .wrapper .line {
        display:inline-block;
        position:absolute;
        z-index:-1;
 
        width:4px;
        background-color:#0f0;
        transform: rotate(90deg);
        transition: all 0.8s ease-out;
        height:200px;
        top:12%
    }
    .wrapper .line::after {
        position: absolute;
        content:"";
        top:0%;
        left:-1px;
        bottom:50%;
        right:-1px;
        background-color:#fff;
    }
    .number {
        width:20px;
        left:140px;
        height:240px;
        display:inline-block;
        position:absolute;
        z-index:-1;
    }
    .number.n0 {
        transform: rotate(-90deg);
        bottom:-80px;
    }
    .number.n25 {
        transform: rotate(-45deg);
    }
    .number.n75 {
        transform: rotate(45deg);
    }
    .number.n180 {
        transform: rotate(90deg);
        bottom:-80px;
    }
    .circle1 {
        position:absolute;
        background-color:#90adff;
        top:72%;
        left:calc(50% - 8px);
        width:20px;
        height:20px;
        border-radius:50% 50%;
    }
    .circle2 {
        position:absolute;
        background-color:#8c20b9;
        top:24px;
        left:calc(150px - 95px);
        width:190px;
        height:190px;
        border-radius:50% 50% 0 0;
        z-index:-2;
    }
    .circle2::after {
        position:absolute;
        content:"";
        height:50%;
        background-Color:#fff;
        top:92px;
        left:0;
        width:101%;
    }
    .circle2::before {
        position:absolute;
        content:"";
        top:5px;
        left:5px;
        background-Color:#fff;
        height:calc(100% - 10px);
        width:calc(100% - 10px);
        border-radius:50% 50% 0 0;
    }
 
 
    .scroll {
        overflow-x:auto;
    }
    .scroll>div {
        width:1000px;
        height:1px;
    }
    </style>
 
</head>
<body>
 
    <h2>Ejemplo con % utilizando scroll sin numeros</h2>
    <div class="wrapper">
        <div>
            <div class="line"></div>
            <div class="circle2"></div>
            <div class="circle1"></div>
        </div>
        <div class="scroll"><div></div></div>
    </div>
 
    <h2>Ejemplo con % utilizando scroll</h2>
    <div class="wrapper">
        <div>
            <div class="line"></div>
            <div class="number n0">0%</div>
            <div class="number n25">25%</div>
            <div class="number n90">50%</div>
            <div class="number n75">75%</div>
            <div class="number n180">100%</div>
            <div class="circle2"></div>
            <div class="circle1"></div>
        </div>
        <div class="scroll"><div></div></div>
    </div>
 
    <h2>Ejemplo con valor utilizando scroll</h2>
    <div class="wrapper">
        <div>
            <div class="line"></div>
            <div class="number n0">0</div>
            <div class="number n25">175</div>
            <div class="number n90">350</div>
            <div class="number n75">525</div>
            <div class="number n180">700</div>
            <div class="circle2"></div>
            <div class="circle1"></div>
        </div>
        <div class="scroll"><div></div></div>
    </div>
 
    <h2>Ejemplo con % utilizando entrada de numero</h2>
    <div class="wrapper">
        <div class="">
            <div class="line"></div>
            <div class="number n0">0%</div>
            <div class="number n25">25%</div>
            <div class="number n90">50%</div>
            <div class="number n75">75%</div>
            <div class="number n180">100%</div>
            <div class="circle2"></div>
            <div class="circle1"></div>
        </div>
        <input type="number" min="0" max="100" value="0">
    </div>
 
    <h2>Ejemplo con valor utilizando entrada de numero</h2>
    <div class="wrapper">
        <div>
            <div class="line"></div>
            <div class="number n0">0</div>
            <div class="number n25">175</div>
            <div class="number n90">350</div>
            <div class="number n75">525</div>
            <div class="number n180">700</div>
            <div class="circle2"></div>
            <div class="circle1"></div>
        </div>
        <input type="number" min="0" max="700" value="0">
    </div>
 
</body>
</html>
 
<script>
// codigo para mover la aguja con el movimiento del scroll
const scroll = document.querySelectorAll(".scroll");
scroll.forEach((el)=>{el.addEventListener("scroll", moverScroll)});
function moverScroll() {
    const max=this.scrollWidth-this.offsetWidth;
    const pos=this.scrollLeft;
    let perCent=(pos*100)/max;
    const result=((perCent*180)/100)+90;
    this.previousElementSibling.querySelector(".line").style.transform="rotate("+result+"deg)";
    this.previousElementSibling.querySelector(".line").style.backgroundColor=getColor(27, perCent/5);
};
 
// codigo para mover la aguja con el valor del input
const number = document.querySelectorAll(".wrapper input[type=number]");
number.forEach((el)=>{el.addEventListener("change", moverNumber)});
function moverNumber() {
    const max=parseFloat(this.max);
    const pos=parseFloat(this.value);
    let perCent=(pos*100)/max;
    perCent=perCent<=100?perCent:100;
    const result=((perCent*180)/100)+90;
    this.previousElementSibling.querySelector(".line").style.transform="rotate("+result+"deg)";
    this.previousElementSibling.querySelector(".line").style.backgroundColor=getColor(27, perCent/5);
};
 
/**
 * Funcion que devuelve un color entre el verde y el rojo dependiendo del valor
 * recibido y el incremento de valor entre un color y el otro
 *
 * @param int stepSize - Este valor determina el incremento entre cada color
 *                       por ejemplo:
 *                       - Si se especifica 1, puede haber 511 colores entre el verde y el rojo (255 de rojo y 255 de verde)
 *                       - Si especificamos 10, puede haber 53 colores entre el verde y el rojo
 *                       - Si especificamos 20, puede haber 27 colores entre el verde y el rojo
 *                       - Si especificamos 63, puede haber 10 colores entre el verde y el rojo
 * @param int value    - Determina el numero de color a mostrar
 *
 * @return string - el valor en hexadecimal del color
 */
function getColor(stepSize, value) {
    let red=0;
    let green=255;
    let result=0;
    red=1*(value*stepSize);
    if (red>255) {
        result=Math.floor((red-255)/stepSize);
        red=255;
        if (result>0) {
            green=green-(result*stepSize);
            if (green<0) {
                green=0;
            }
        }
    }
    return "#"+intToHex(red)+intToHex(green)+intToHex(0);
}
 
/**
 * Converts integer to a hexidecimal code, prepad's single
 * digit hex codes with 0 to always return a two digit code.
 *
 * @param {Integer} i Integer to convert 
 * @returns {String} The hexidecimal code
 */
function intToHex(i) {
    var hex = parseInt(i).toString(16);
    return (hex.length < 2) ? "0" + hex : hex;
}
</script>



Comentarios sobre la versión: 1 (2)

Imágen de perfil
21 de Septiembre del 2019
estrellaestrellaestrellaestrellaestrella
Muy bueno!!!
Responder
Imágen de perfil
21 de Septiembre del 2019
estrellaestrellaestrellaestrellaestrella
¡Magistral!
Responder

Comentar la versión: 1

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s5542