Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a slide element in an event, in Slick Carousel?

Slick Carousel: http://kenwheeler.github.io/slick/

How can I get the element of the slide in an event? For example:

   .on('afterChange', function (slick, currentSlide)
   {
      var currentSlideElement = //Get current slide element here
   });

The first argument seems to be the event object, but its target (or currentTarget) is always the slides container, and second argument seems to be the slick object....

like image 402
Yuval A. Avatar asked Mar 18 '15 17:03

Yuval A.


3 Answers

you need to include the first argument "event" like this

$('.your-element').on('afterChange', function(event, slick, currentSlide){
  console.log(currentSlide);
});    

or else your "currentSlide" argument will be "slick"

like image 163
Abraham Uribe Avatar answered Oct 11 '22 10:10

Abraham Uribe


To get the DOM element on 'afterChange' event:

$('.your-element').on('afterChange', function (event, slick, currentSlide) {
    var elt = slick.$slides.get(currentSlide);
});
like image 36
Vénizia Avatar answered Oct 11 '22 09:10

Vénizia


// Get the current slide
var currentSlide = $('.your-element').slick('slickCurrentSlide');

Source: https://github.com/kenwheeler/slick

like image 4
Leonid Usachov Avatar answered Oct 11 '22 10:10

Leonid Usachov