Я использую Bootstrap на своем сайте, а также слайдер-карусель, и он работает нормально.
Проблема в том, что когда ползунок перемещает изображение справа налево, он принимает второе изображение, когда первое изображение полностью достигает левого края. Это означает, что в течение 1 мс или 2 мс между слайдами будет отображаться пустое пространство. Мне не нужно это пустое пространство, и я хочу, чтобы ползунок перемещался справа налево. Второе изображение должно появиться сразу после первого.
Я хочу создать такое
.carousel-item {
perspective: 1000px;
transform-style: preserve-3d;
}
.carousel-item img {
object-fit: cover;
width: 100%;
height: 100%;
}
.carousel-inner {
display: flex;
flex-wrap: nowrap;
/* Prevent items from wrapping */
gap: 1rem;
/* Add some space between carousel items */
overflow: hidden;
/* Hide the overflow to prevent extra spacing */
perspective: 1000px;
}
.carousel-item {
flex: 0 0 calc(33.333333% - 1rem);
/* Calculate the width with gap */
transform: translateZ(-200px);
backface-visibility: hidden;
}<link href = "https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel = "stylesheet">
<div id = "carouselExample" class = "carousel slide" data-bs-ride = "carousel">
<div class = "carousel-inner">
<div class = "carousel-item active">
<img src = "https://placehold.co/800x400" class = "d-block w-100" alt = "Image 1">
</div>
<div class = "carousel-item">
<img src = "https://placehold.co/800x400" class = "d-block w-100" alt = "Image 2">
</div>
<div class = "carousel-item">
<img src = "https://placehold.co/800x400" class = "d-block w-100" alt = "Image 3">
</div>
<!-- Add more carousel items as needed -->
</div>
<button class = "carousel-control-prev" type = "button" data-bs-target = "#carouselExample" data-bs-slide = "prev">
<span class = "carousel-control-prev-icon" aria-hidden = "true"></span>
<span class = "visually-hidden">Previous</span>
</button>
<button class = "carousel-control-next" type = "button" data-bs-target = "#carouselExample" data-bs-slide = "next">
<span class = "carousel-control-next-icon" aria-hidden = "true"></span>
<span class = "visually-hidden">Next</span>
</button>
</div>
<script src = "https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"></script>Там вы видите пустое пространство, поэтому я хочу, чтобы мое следующее изображение появилось после предыдущего.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Если вам нужны продвинутые карусели, вам следует использовать специализированную библиотеку, например: Swiper
Я не рекомендую использовать slick, как предлагает GrafiCode, он не поддерживается с 2017 года.
Вот пример, который выглядит так, как вы хотите: https://codepen.io/iamdineshbasnet/pen/XWxpjaQ
var swiper = new Swiper(".mySwiper", {
effect: "coverflow",
centeredSlides: true,
autoplay: {
delay: 3000,
disableOnInteraction: false
},
loop: true,
slidesPerView: "2",
coverflowEffect: {
rotate: 0,
stretch: 30,
depth: 100,
modifier: 5,
slideShadows: true
},
navigation: {
prevEl: ".swiper-button-prev",
nextEl: ".swiper-button-next"
},
pagination: {
el: ".swiper-pagination",
clickable: false
}
});html,
body {
position: relative;
height: 100vh;
}
body {
background: #eee;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 14px;
color: #000;
margin: 0;
padding: 0;
display: flex;
align-items: center;
justify-content: center;
background: #000;
}
.swiper {
max-width: 600px;
width: 100%;
padding-bottom: 50px !important;
}
.swiper-slide {
background-position: center;
background-size: cover;
width: 320px !important;
height: 200px !important;
overflow: hidden;
border-radius: 8px;
}
.swiper-slide.swiper-slide-visible.swiper-slide-active {
transition: all 0.3s !important;
}
.swiper-slide-visible.swiper-slide-next,
.swiper-slide-visible.swiper-slide-prev {
transition: all 0.5s !important;
}
.swiper-slide img {
display: block;
width: 100%;
object-fit: cover;
}
.swiper-controller {
position: relative;
margin-top: 80px;
display: flex;
gap: 10px;
/* justify-content: space-between; */
z-index: 1111;
}
.swiper-button-next {
margin-right: 150px;
}
.swiper-button-prev {
margin-left: 150px;
}
.slider-arrow {
box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
border-radius: 50%;
width: 30px !important;
height: 30px !important;
cursor: pointer;
background: #fff;
}
.slider-arrow::after {
content: "";
}
.slider-arrow .icon {
position: relative;
z-index: 11111111111;
color: black;
font-size: 16px;
font-weight: 500;
pointer-events: all;
cursor: pointer;
}
.swiper-pagination {
transform: translateY(50%) !important;
}
.swiper-pagination-bullet {
width: 10px !important;
height: 4px !important;
border-radius: 4px !important;
transition: all 0.3s;
background: #ffffff;
}
.swiper-pagination-bullet-active {
width: 20px !important;
background: #ffffff;
}<script src = "https://unpkg.com/swiper/swiper-bundle.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/Swiper/9.2.4/swiper-bundle.min.js"></script>
<link href = "https://unpkg.com/swiper/swiper-bundle.min.css" rel = "stylesheet"/>
<link rel = "stylesheet" href = "https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200" />
<!-- Swiper -->
<div class = "swiper mySwiper">
<div class = "swiper-wrapper">
<div class = "swiper-slide">
<img src = "https://swiperjs.com/demos/images/nature-2.jpg" />
</div>
<div class = "swiper-slide">
<img src = "https://swiperjs.com/demos/images/nature-3.jpg" />
</div>
<div class = "swiper-slide">
<img src = "https://swiperjs.com/demos/images/nature-4.jpg" />
</div>
<div class = "swiper-slide">
<img src = "https://swiperjs.com/demos/images/nature-5.jpg" />
</div>
<div class = "swiper-slide">
<img src = "https://swiperjs.com/demos/images/nature-6.jpg" />
</div>
</div>
<div class = "swiper-controller">
<div class = "slider-controller">
<div class = "swiper-button-prev slider-arrow">
<span class = "material-symbols-outlined icon ">
arrow_back
</span>
</div>
<div class = "swiper-button-next slider-arrow">
<span class = "material-symbols-outlined icon">
arrow_forward
</span>
</div>
<div class = "swiper-pagination"></div>
</div>
</div>
Карусель начальной загрузки не предлагает такие параметры, как «сколько слайдов показывать», «сколько слайдов прокручивать», «центральный режим». Пожалуйста, рассмотрите слайдер в качестве альтернативы: kenwheeler.github.io/slick Пример «центрального режима» довольно близок к тому, что вы ищете,