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

151
Vistas
I am trying to set the z-index for an image but it's not working

I am trying to set the z-index for an image, but it's not working. Actually, the position is absolute and also, I've checked the parents z-indexes with this code to be sure that z-index is none.

var el = document.getElementById("bear-moving"); // or use $0 in chrome;
do {
    var styles = window.getComputedStyle(el);
    console.log(styles.zIndex);
} while(el.parentElement && (el = el.parentElement));

My image is moving according to the scroll and it needs to be centered. If I set the z-index, it will work only before it starts to move.

This code represents the JS to move the image.

var container = document.getElementsByClassName('elementor-element-192d237');
var image1 = document.getElementById('bear-moving');
var index = 0;
document.addEventListener("scroll", () => {

    div = document.querySelector(".elementor-element-192d237");
  if(parseInt(div.getBoundingClientRect().top)-300 < 0 && parseInt(div.getBoundingClientRect().bottom)>430) {
      var style_top = 0;
    while (style_top<window.innerHeight/2-div.getBoundingClientRect().top-25) {
        style_top = style_top+5;
        image1.style.top = style_top + 'px';
    }

  }
})

enter image description here

enter image description here

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

0

After hours of trying to set the z-index and guessing what's the problem, I figured out that it is a background transparent image...

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