dawn
dawn

Reputation: 1005

Slick Carousel unable to initialize method

I have several instances of the Slick Carousel gallery set up and working properly. However, I cannot successfully call the Methods as described in the documentation. Whenever I try to execute a method after initialization is complete,the method did not perform. I'm trying to automatically goto the first slide after the slick is initiated.(the mothod "onInit " and "onReInit " is not perform.)

this is my code:

$("body #slick").slick({
    slidesToShow: 3,
    centerPadding: "20px",
    draggable:false,
    onInit:function(){
      console.log("onInit");
      $("body #slick").slick("slickGoTo",0);
    },
    onReInit:function(){
      console.log("onReInit");
      $("body #slick").slick("slickGoTo",0);
    }
  });

thanks for help me.

Upvotes: 1

Views: 4122

Answers (1)

Catalyst
Catalyst

Reputation: 1018

According to the release notes here:

All callback methods are now deprecated. They have been replaced with event triggers. I added a few helpful ones too. So onAfterChange is now:

$('.your-element').on('afterChange', function(){
    // do stuff
});

So, in your case:

$("body #slick").on('init', function() {
    console.log("onInit");
    $("body #slick").slick("slickGoTo",0);
});

$("body #slick").on('reInit', function() {
    console.log("onReInit");
    $("body #slick").slick("slickGoTo",0);
});

$("body #slick").slick({
    slidesToShow: 3,
    centerPadding: "20px",
    draggable:false
});

Please note that all event handlers should be declared before calling slick({...}).

Upvotes: 2

Related Questions