Hi there,
I’m encountering a bug with my slider. I want to integrate a static element into this CMS slider:
The top is static, the bottom is the slider.
Integrating the static element works but the slider doesn’t always take into account that a new element got into the collection list and doesn’t update the bullet point down there.
The problem is that this is acting as there’s one less slide, so the last slide is not visible.
yet, sometimes, when refreshing the page, the slide IS taken into account and one more bullet appears in the nav:
Clearing the cache and reloading the page usually works. But I cannot have a solution that renders what I want 1/10 times…
Here’s my slider’s code:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.css"/>
<script src="https://cdn.jsdelivr.net/npm/swiper@8/swiper-bundle.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", () => {
document.querySelectorAll(".slider_2_wrap").forEach((wrap) => {
if (wrap.dataset.scriptInitialized) return;
wrap.dataset.scriptInitialized = "true";
const cmsWrap = wrap.querySelector(".slider_2_cms_wrap");
if (!cmsWrap) {
console.warn("Missing required elements for Swiper in:", wrap);
return;
}
const swiper = new Swiper(cmsWrap, {
slidesPerView: "auto",
followFinger: true,
freeMode: false,
slideToClickedSlide: false,
centeredSlides: false,
autoHeight: false,
speed: 600,
mousewheel: {
forceToAxis: true,
},
keyboard: {
enabled: true,
onlyInViewport: true,
},
// rewind slides when clicking next or prev
rewind: true,
// Autoplay slides with a duration
autoplay: {
delay: 5000,
disableOnInteraction: false,
},
pagination: {
el: wrap.querySelector(".slider_2_bullet_wrap"),
bulletActiveClass: "is-active",
bulletClass: "slider_2_bullet_item",
bulletElement: "button",
clickable: true,
},
scrollbar: {
el: wrap.querySelector(".slider_2_draggable_wrap"),
draggable: true,
dragClass: "slider_2_draggable_handle",
snapOnRelease: true,
},
slideActiveClass: "is-active",
slideDuplicateActiveClass: "is-active",
});
});
});
</script>