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

144
Visualizações
Slideshow elements overlapping each other on window resize

I have a slideshow on my website which consists of 3 slides. I basically followed this tutorial www.youtube.com/watch?v=VYsVOamdB0g&t including part 2 from Kevin Powell. Everything is the same, but there is a problem with overlapping elements when I resize the screen. I created an event listener when someone resizes the screen, and the code is:

var windowSize = innerWidth; //width of the screen
var slideWidth = slides[0].getBoundingClientRect().width; // width of the slide


const setSlidePosition = (slide, index) => {
    var newWindowSize = innerWidth;
    const scaleFac = newWindowSize/windowSize; 
    windowSize = newWindowSize;
    slideWidth *= scaleFac;
    slide.style.left= slideWidth * index + 'px';
}

slides.forEach(setSlidePosition);  

window.addEventListener('resize', setSlidePosition); // whenever someone resizes screen

The code works whenever someone makes the screen smaller, but when someone makes the screen larger than the original, the elements overlap:

Before resize:

Before resize

After resize:

After resize

about 4 years ago · Juan Pablo Isaza
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