left of second slide should be one slide’s width.
left of third slide should be two slide’s width.
We need to find the width of one slide first. We can get the width of one slide with getBoundingClientRect. In this case, Getting the width of the first slide is sufficient.
const rect = slides[0].getBoundingClientRect()
console.log(rect)
We can get the width of one slide with the width property from getBoundingClientRect.
const rect = slides[0].getBoundingClientRect()
const slideWidth = rect.width
console.log(slideWidth) // 936 (This may be a different number in your case. It depends on the width of your browser).
You can shorten the code above slightly by chaining properties together.
Notice we can use the index of each slide to calculate the correct left value? Since you see this pattern now, let’s switch to a forEach loop to position the slides.