Slick.js customizing dots
Asked Answered
R

3

6

I am trying to customize the standard dots that come with slick.js. I have a class "transparent-circle" that I want to use as dots and when the dot is active I want to use the class "active"

This what my classes look like:

.transparent-circle {
  border: 2px solid #fff;
  height:12px;
  width:12px;
  -webkit-border-radius:75px;
  -moz-border-radius:75px;
}

.active{
  background-color: rgba(126, 222, 186, 1);
  border: 2px solid #7EDEBA !important;
}

Here's what I've tried to customize the dots. I've been trying to do it with jquery in my document.ready function

$('.slick-dots li button').remove();
$('.slick-dots li').addClass('transparent-circle');

So I want to remove the standard buttons and add the css class to the list items but nothing seems to be happening, unfortunately

Ruggles answered 11/3, 2016 at 10:28 Comment(0)
D
4

You have to run your functions after Slick initialized.

So this is an example , using on init

Add this before your setup :

$('.your-element').on('init', function(event, slick){
   var $items = slick.$dots.find('li');
   $items.addClass('transparent-circle');
   $items.find('button').remove();
});

// Setup
$('.your-element').slick({
   // ....
});
Dynatron answered 11/3, 2016 at 10:58 Comment(2)
This is genius! Thanks a lot friend! I now need to find a way to inject the active class instead of the standard slick-active classRuggles
@I2aelba what would you recommend to switch the slick-active class with active?Ruggles
C
4

In external script file

$(document).ready(function(){
$(".your-slider").slick({
    dots: true,
    customPaging: function(slider, i) {      
      return '<div class="custom-slick-dots" id=' + i + "></div>";
    }
  });
});

Apply your styles to .custom-slick-dots

Then for the active state, apply your styles to .slick-active .custom-slick-dots

You can customise the div as you wish.

P.S. Sorry if this is not a tailored answer...it's more of a general one for anyone who needs it. 😬

Canikin answered 19/8, 2020 at 2:58 Comment(0)
B
0

try:

$('#yourID').slick({
        ...,
        customPaging: function(slider, i) {
            return ''; // Remove button, customize content of "li"
        }
    });

$('#yourID .slick-dots li').addClass('transparent-circle'); //  Add class to "li"
Bergson answered 11/3, 2016 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.