I am trying to achieve something which I haven't seen done so far on the web. I want the active pagination dot in the slick slider to always be in the center.
This is the expected result:
In other words I would expect the page to load showing the first slide but the pagination dot for the first slide should be centered.
If a user clicks the next slide by swiping then the dot should move the middle again, with the active slide always being centered in the pagination. Any ideas on the best way to achieve this?
Here's an example and code of what i've done so far.
$('.slider').slick({
infinite: true,
dots: true,
arrows: false
});
.slider {
width: 200px;
}
.slide img {
display: block;
width: 100%;
height: auto;
}
.slick-dots {
display: flex;
justify-content: center;
margin: 0;
padding: 1rem 0;
list-style-type: none;
}
.slick-dots li {
margin: 0 0.25rem;
}
.slick-dots button {
display: block;
width: 1rem;
height: 1rem;
padding: 0;
border: none;
border-radius: 100%;
background-color: grey;
text-indent: -9999px;
}
.slick-dots li.slick-active button {
background-color: blue;
}
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha256-3edrmyuQ0w65f8gfBsqowzjJe2iM6n0nKciPUp8y+7E=" crossorigin="anonymous"></script>
<script type="text/javascript" src="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.min.js"></script>
<link rel="stylesheet" type="text/css" href="//cdn.jsdelivr.net/npm/[email protected]/slick/slick.css" />
<div class="slider">
<div class="slide">
<img src="http://placehold.it/200x100?text=1" />
</div>
<div class="slide">
<img src="http://placehold.it/200x100?text=2" />
</div>
<div class="slide">
<img src="http://placehold.it/200x100?text=3" />
</div>
<div class="slide">
<img src="http://placehold.it/200x100?text=4" />
</div>
<div class="slide">
<img src="http://placehold.it/200x100?text=5" />
</div>
</div>
beforeChange
andàfterChange
to start a css animation. How the animation looks like, I dont know. But you can add a class to for the current Position – Krohn