<script>
window.onload = function () {
if (typeof window !== 'undefined') {
const slider = document.querySelector('#demo-swiper-js-slides');
const indicators = document.querySelectorAll('.demo-swiper-js-indicators span');
slider.addEventListener('scroll', () => {
updateActiveIndicator();
});
function updateActiveIndicator() {
const { scrollLeft, clientWidth } = slider;
const activeIndex = Math.round(scrollLeft / clientWidth);
indicators.forEach((indicator, index) => {
if (index === activeIndex) {
indicator.dataset.active = true;
} else {
indicator.dataset.active = false;
}
});
}
updateActiveIndicator();
}
};
</script>
<div class="product">
<div class="demo-slide-show">
<div class="demo-slide-show-slides" id="demo-swiper-js-slides">
<figure id="slide1" class="demo-slide-show-slide">
<img src="/demo-images/1.png" alt="" />
</figure>
<figure id="slide2" class="demo-slide-show-slide">
<img src="/demo-images/2.png" alt="" />
</figure>
<figure id="slide3" class="demo-slide-show-slide">
<img src="/demo-images/3.png" alt="" />
</figure>
<figure id="slide4" class="demo-slide-show-slide">
<img src="/demo-images/4.png" alt="" />
</figure>
</div>
<div class="demo-swiper-js-indicators">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
</div>
<h4>Syntax Basketball</h4>
<p>$42.00</p>
</div>
<style>
.product {
--demo-slide-show-size: 300px;
margin-inline: auto;
width: var(--demo-slide-show-size);
}
.demo-slide-show {
position: relative;
border-radius: 10px;
}
.slider__nav {
position: absolute;
display: flex;
justify-content: space-between;
width: 140%;
inset: 0 -20%;
z-index: 0;
button {
border: none;
cursor: pointer;
transition: 0.2s ease opacity;
&:first-child {
opacity: 0;
}
}
}
.demo-slide-show-slides {
z-index: 1;
position: relative;
display: flex;
align-items: center;
overflow-x: scroll;
scroll-snap-type: x mandatory;
overscroll-behavior-x: contain;
border-radius: 10px;
}
.demo-slide-show-slide {
margin: 0;
scroll-snap-align: start;
flex-shrink: 0;
display: flex;
align-items: center;
justify-content: center;
width: var(--demo-slide-show-size);
}
.demo-slide-show-slide > img {
max-width: 100%;
height: 100%;
object-fit: contain;
}
.demo-swiper-js-indicators {
position: absolute;
bottom: 10px;
inset-inline: 0;
justify-content: center;
display: flex;
gap: 10px;
z-index: 2;
span {
block-size: 10px;
inline-size: 10px;
border-radius: 50%;
background-color: #ccc;
opacity: 0.8;
&[data-active='true'] {
background-color: #fff;
scale: 1.3;
opacity: 1;
}
}
}
</style>
<!-- TODO clean up classes and names -->