question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

focusOnSelect doesn't work when a filter is applied to synced sliders

See original GitHub issue

A very simple issue which could be simulated like this:

Set up

  • 2 synced sliders
  • slider#2 set up:
    • slidesToShow > 1 (e.g. 3)
    • focusOnSelect = true
  • a filter which filters both sliders (e.g. ‘:even’)

Expected and Actual behavior

Once the filter has been applied to both sliders, clicking on slider-nav items should navigate to the same items in slider-for. Instead, Slick navigates to a wrong item, in some crazy manner.

Test Case

Try clicking on slide3 text => and then on slide7 in this jsFiddle test case.

Bug Explanation

Slide attribute data-slick-index, which is used for navigation, cannot be relied on once a filter has been applied. Natural order of slides should be used instead. Fix is to follow…

Issue Analytics

  • State:open
  • Created 9 years ago
  • Reactions:1
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
tsymbalcommented, Sep 6, 2017

My variant of solution, based on previous “codepens”.

.gallery_slider - main slider .gallery_thumbs - thumbs slider .filternav ul li a - filter links (albums), their href=“#id” (id = album id), all slides (in both sliders) have id as “class” value. So, each slide can be in several albums. For example, clicking on link with href=“#dir1” will filter all slides (in both sliders), that have class=“… dir1 …”

    $('.gallery_slider').slick({
        slidesToShow: 1,
        slidesToScroll: 1,
        arrows: true,
        fade: false,
        infinite: false,
        asNavFor: '.gallery_thumbs'
    });
    $('.gallery_thumbs').slick({
        slidesToShow: 4,
        slidesToScroll: 1,
        infinite: false,
        asNavFor: '.gallery_slider',
        dots: false,
        centerMode: false,
        focusOnSelect: true,
        arrows: true,
    });
    $(document).on('click', '.filternav ul li a', function(a){
        a.preventDefault();
        $(".filternav ul li").removeClass("active");
        $(this).parents("li").addClass("active");
        href = $(this).attr("href").replace("#","");
        console.log(href);
        var $slider = $('.gallery_slider, .gallery_thumbs');
        $slider.slick('slickUnfilter').slick('slickFilter','.'+href);
        $slider.each(function(index,slide){
            s_id = 0;
            //console.log(index,slide,s_id);
            $(".slick-slide:not(.slick-cloned)",slide).each(function(s_index,s_slide) {
                $(this).attr("data-slick-index",s_id)
                s_id = s_id+1;
                if (index==0) {
                    if ($(this).hasClass("slick-current")) {
                        active_index = s_id;
                    }
                }
                if (index==1) {
                    if (s_id==active_index) {
                        $(this).addClass("slick-current");
                    } else {
                        $(this).removeClass("slick-current");
                    }
                }
            })
        })
        $slider.slick('slickGoTo',0,true);
    });
2reactions
Colircommented, Jan 31, 2017

base on the solution of @LucasFlicky , here is a working version without plugin’s core modifications http://codepen.io/Colir/pen/PWQqEE

Read more comments on GitHub >

github_iconTop Results From Across the Web

jQuery Slick carousel filtering not working when used with ...
The code for slide filtering based on product color (which is when the selected variant is equal to the image alt) which doesn't...
Read more >
slick - the last carousel you'll ever need - Ken Wheeler
slick is a responsive carousel jQuery plugin that supports multiple breakpoints, CSS3 transitions, touch events/swiping & much more!
Read more >
kenwheeler/slick - Gitter
Hi. "afterchange" method is not working on devices. I have the slider with images and videos slide next item automatically if the current...
Read more >
Solved: slicer & filter not in sync - Microsoft Power BI Community
Solved: hello, i want to ask, why my filter & slicer not in sync, like if i choose ... the filter page doesnt...
Read more >
bd-slick-carousel - npm
To start working with Slick right away, there's a couple of CDN ... asNavFor, string, $(element), Enables syncing of multiple sliders.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found