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.

Impossible to determine slide direction in `beforeChange` handler with 2 slides

See original GitHub issue

short description of the bug / issue, provide more detail below.

The only parameters we get for the beforeChange handler are event, slick, currentSlide, nextSlide. There is no direction parameter. Therefore, going from currentSlide 0 to nextSlide 1 has ambiguous direction that is impossible to determine without knowing more information. Direction can be calculated if there are more than 2 slides because going left nextSlide would be numSlides -1 which can be used as an exception case in calculating direction.

We simply need a direction parameter to be passed to this handler.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

3reactions
qikkeronlinecommented, May 28, 2016

For anyone who needs this behaviour today:

init slick without arrows

    $(".frontpage-slider").slick({
        arrows: false, // disable built in arrows
    });

then implement your own next and prev buttons in your html and implement the following js

    var direction;

    $(document).on('click', '.slick-next', function(){

        direction = 'right';
        $('.frontpage-slider').slick('slickNext');

    });

    $(document).on('click', '.slick-prev', function(){

        direction = 'left';
        $('.frontpage-slider').slick('slickPrev');

    });

And afterwards you can use the direction variable in your beforeChange event 😃

In my case the animations I trigger on the beforeChange event are turned off on mobile devices; hence the above suffices for me. If you need the animations to work on touch devices you’ll need some extra logic.

I still think this would be a great addition to the Slick core; would make an already awesome slider even more awesome 👍

0reactions
eballestecommented, May 27, 2020

@notacouch didn’t think about that, maybe by also listening in on the keypress event and checking if it was the enter key should take care of that. oh, also adding the aria button role to it?

regardless, i’ve been saying this in every single issue that I get a new notification from, this project is dead. issues should be reaching 1000 issues now and the only recent pull request was a cosmetic update to show more accurate download numbers in npm.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to detect slide direction in Slick Carousel ...
beforeChange event get you an access to currentSlide and nextSlide values. It works for infinite sliders too. So, the code is:
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
"using {infinite: false} , and beforeChange event to slick("goto", 0) if the next slide > total slides " didn't work, it works same...
Read more >
„‚ THREE APPROACHES TO ORGANIZATIONAL LEARNING
Conceptually, organization development is different from both management training and management development. The latter two kinds of learning may, however, be ...
Read more >
Fully Responsive & Flexible jQuery Carousel Plugin - slick
Slick is a feature-rich jQuery slider plugin for creating highly ... 2. Wrap the Html contents you want to slide in DIV elements....
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