eggplantSword's avatar

How to create a section where some images loop over and over

Sorry about the confusing title, I don't know what that's called but basically I want an image section that displays 4 images and once and loops through an array of images that when the last one is showed the first one appears again behind it, so the images never end.

This is what I have so far however I can't get the loop to work.

I think the problem is in endSlide but I'm not sure. My logic for that part was if I assume the total slides are 10, then if the slideNumber is 8 then the endSlide should be 8+4=12 -> 12-(10-1)=1

How can I fix it so that it loops smoothly? here is the code on a codesandbox so you can see what I mean https://codesandbox.io/p/sandbox/3xnnjt

0 likes
3 replies
vincent15000's avatar

What you want to do is called a carousel or a slider.

There are a lot of examples in many different languages on the web.

eggplantSword's avatar

@vincent15000 I haven't been successful in finding one that is multiple images, that loops around and autoplays with no controls. I modified an example I found of a single image slider and came up with the above code, I feel like I'm close but missing something small. I'll keep looking for examples online.

1 like
Deathgods46's avatar

Hi, you can try react-slick if it is the environment in react. Or you can search for slider. You must be able to find something around it.

1 like

Please or to participate in this conversation.