Slick: Multiple dots navigation

Created on 30 Jan 2015  路  5Comments  路  Source: kenwheeler/slick

I need dots inside every slide. I have something like that:

$('.homepage-slider').slick({
    dots: true,
    appendDots: ".slide"
});

Dots are attached correctly, but dot for current slide is marked as active only in first slide.

Most helpful comment

This is my Quick 'n Dirty version:

var activeClass = 'slick-active',
    ariaAttribute = 'aria-hidden';
$( '.slider' )
.on( 'init', function() {
    $( '.slick-dots li:first-of-type' ).addClass( activeClass ).attr( ariaAttribute, false );
} )
.on( 'afterChange', function( event, slick, currentSlide ) {
    var $dots = $( '.slick-dots' );
    $( 'li', $dots ).removeClass( activeClass ).attr( ariaAttribute, true );
    $dots.each( function() {
        $( 'li', $( this ) ).eq( currentSlide ).addClass( activeClass ).attr( ariaAttribute, false );
    } );
} );

$( '.slider' ).slick();

Not pretty, but it works for me.

All 5 comments

I'm struggling to understand the use case. If you had dots in each slide, couldn't you just put dots in each slide and use the slideIndex to mark active? Get the number by getting the slideCount?

The use case is kind of a design decision - the navigation is within the slide and rather than absolutely position a div outside the slide but on top of it, it makes more sense to duplicate the markup for the visual effect.

Because appendDots will put the dots on every slide, one would think that they would all reflect changes to the slider state as well, perhaps out of the box.

This is my Quick 'n Dirty version:

var activeClass = 'slick-active',
    ariaAttribute = 'aria-hidden';
$( '.slider' )
.on( 'init', function() {
    $( '.slick-dots li:first-of-type' ).addClass( activeClass ).attr( ariaAttribute, false );
} )
.on( 'afterChange', function( event, slick, currentSlide ) {
    var $dots = $( '.slick-dots' );
    $( 'li', $dots ).removeClass( activeClass ).attr( ariaAttribute, true );
    $dots.each( function() {
        $( 'li', $( this ) ).eq( currentSlide ).addClass( activeClass ).attr( ariaAttribute, false );
    } );
} );

$( '.slider' ).slick();

Not pretty, but it works for me.

It is worked for me but there is speed delay.

$dots is already in the slick object

.on( 'afterChange', function( event, slick, currentSlide ) {
  $.each(slick.$dots, (i, el) => {
    $(el).find('li').eq(currentSlide).addClass('slick-active').find('button');
  })
});
Was this page helpful?
0 / 5 - 0 ratings

Related issues

NozX18 picture NozX18  路  3Comments

rahi-rajeev picture rahi-rajeev  路  3Comments

crstauf picture crstauf  路  3Comments

eirikrlee picture eirikrlee  路  3Comments

REPTILEHAUS picture REPTILEHAUS  路  3Comments