There is a certain list of images, which is divided into a number, and subsequently displayed in the form of a "carousel".

<div> <img src="img1.jpg" /> <img src="img1.jpg" /> <img src="img1.jpg" /> </div> <div> <img src="img1.jpg" /> <img src="img1.jpg" /> <img src="img1.jpg" /> </div> <div> <img src="img1.jpg" /> <img src="img1.jpg" /> </div> 

And there is the possibility of removing these photos. Tobish, click on the desired photo, click the delete button, and it is deleted. But the fact is that if you delete somewhere in the middle of the list, there will be a space between these photos. We must remove it. that is, to do so to say, sorting, so that it does not:

 <div> <img src="img1.jpg" /> <img src="img1.jpg" /> <img src="img1.jpg" /> </div> <div> <img src="img1.jpg" /> <img src="img1.jpg" /> </div> <div> <img src="img1.jpg" /> <img src="img1.jpg" /> </div> 

and something like:

 <div> <img src="img1.jpg" /> <img src="img1.jpg" /> <img src="img1.jpg" /> </div> <div> <img src="img1.jpg" /> <img src="img1.jpg" /> <img src="img1.jpg" /> </div> <div> <img src="img1.jpg" /> </div> 

Who has any ideas? :)

    2 answers 2

    Perhaps it is worth trying instead of directly deleting a photo, simply replacing it with one of the photos from the last block. But it will work if the photos are not sorted according to some specific order, but simply formed into groups initially.

    • Initially did so. :) Now I rewrote the code a bit so that there was no separation of pictures by 5 pieces, and all the pictures were output in a row, and JS, already divided into the required number. ) - Eugene

    if to tear out an array of all src of a set $ ('img') and then a cycle to assign them (excluding empty values ​​from an array)?