Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
Can i manipulate a specific part of a css property value?

What i want?

I want to manipulate a specific part of a css property value with an HTML range input.

/* an example CSS */
.background-img {
background-image: linear-gradient(rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0.5)),
    url(wallpaper.jpg);
}

Let's say i want to change only the alpha (opacity) parts of this css rgba code with my html range input here;

<input
 class="range-input"
 type="range"
 min="0"
 max="0.999"
 value="0.5"
 step="0.010"
                />

Is it a possible thing to manipulate a specific part of a css property value with js? How can i connect this html input element into background-image css property value, not to whole value but the opacity part or parts.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The following might serve as a starting point for what you are trying to do:

var input = document.getElementById("range-input");
let root = document.documentElement;

input.onchange = function()
{
  root.style.setProperty('--opacity', input.value);
};
:root {
  --opacity: 1.0;
}

.background-img {
width: 200px;
height: 100px;
background-size: 200px 100px;
background-image: url(https://variety.com/wp-content/uploads/2021/07/Rick-Astley-Never-Gonna-Give-You-Up.png?w=1024);
opacity: var(--opacity);
}
<input
 class="range-input"
 id="range-input"
 type="range"
 min="0"
 max="0.999"
 value="0.5"
 step="0.010"
                />

<div class="background-img"></div>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda