The source script that I am analyzing is here.
var itemClassName = "carousel__photo";
items = d.getElementsByClassName(itemClassName),
totalItems = items.length,
slide = 0,
moving = true;
// Set classes
function setInitialClasses() {
// Targets the previous, current, and next items
// This assumes there are at least three items.
items[totalItems - 1].classList.add("prev");
items[0].classList.add("active");
items[1].classList.add("next");
}
To understand better I initially assume only 3 slides. In that case:
items[totalItems - 1] → This will be items[2].
So why on the third item we are putting calls prev
Currently, only the first one(items[0]
) is visible.