Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda