My code is very long. I can not show you all here. I just show the javascript code only
My javascript like this :
Here's my answer: http://phpfiddle.org/main/code/0h1g-mvus
I just shift the images instead. You might need to do some changes to pass values or w/e.
let current = 0;
for(let i = 0; i < 5; i++) {
$('#thumbnail-view-delete-'+i).click(function(){
current -= 1;
$('input[name="photo-'+i+'"]').val('');
document.getElementById("thumbnail-view-li-"+current).style.display = "none";
document.getElementById("thumbnail-upload-li-"+current).style.display = "";
document.getElementById("thumbnail-upload-li-"+(current+1)).style.display = "none";
document.getElementById("thumbnail-slot-li-"+(current+1)).style.display = "";
shift_image(i);
});
}
function shift_image(start)
{
let finish = 4;
for (; start < finish - 1; start++)
{
let next = $('#thumbnail-view-'+(start+1)).attr('src');
$('#thumbnail-view-'+start).attr('src', next);
}
}