// Carousel
const myCarousel = document.getElementById('carouselExampleIndicators')
const indicatorsContainer = myCarousel.querySelector(".carousel-indicators")
const indicators = myCarousel.querySelectorAll(".carousel-indicators button")
const inner = myCarousel.querySelectorAll(".carousel-inner div")
const lengElements = indicators.length
let centerLenthElement;
if (lengElements % 2 === 0) {
centerLenthElement = lengElements / 2
} else {
centerLenthElement = lengElements / 2 + 0.5
}
for (let i = 0; i < lengElements; i++) {
if ((i + 1) === centerLenthElement ) {
indicators[i].classList.add("active")
inner[i].classList.add("active")
} else {
indicators[i].classList.remove("active")
inner[i].classList.remove("active")
}
}
myCarousel.addEventListener('slide.bs.carousel', event => {
console.log("event.direction", event.direction)
if (event.direction === "left") {
const indicatorFirst = myCarousel.querySelector(".carousel-indicators > button")
const clone = indicatorFirst.cloneNode(true)
indicatorFirst.remove()
indicatorsContainer.append(clone)
} else {
const indicatorLast = myCarousel.querySelector(".carousel-indicators > button:last-child")
const clone = indicatorLast.cloneNode(true)
indicatorLast.remove()
indicatorsContainer.prepend(clone)
}
})
function setActive() {
indicators.forEach((item) => {
item.classList.remove('nearctive');
});
for (let i = 0; i < lengElements; i++) {
if ((i + 1) === centerLenthElement ) {
indicators[i].classList.add("active")
inner[i].classList.add("active")
if (indicators[i].previousElementSibling) {
indicators[i].previousElementSibling.classList.add('nearctive');
} else indicators[lengElements - 1].nextElementSibling.classList.add('nearctive');
if (indicators[i].nextElementSibling) {
indicators[i].nextElementSibling.classList.add('nearctive');
} else indicators[0].nextElementSibling.classList.add('nearctive');
} else {
indicators[i].classList.remove("active")
inner[i].classList.remove("active")
}
}
}
Может просто поиграться с background-size, задать ему contain.