Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!