Detect when slick slider initialises
Asked Answered
T

1

23

I'm trying to fire some code when slick initializes. Apparently in the newest version 1.4 "callback methods have been deprecated and replaced with events."

This doesn't work for me though:

$('.spv-slider').on('init', function(event, slick){
    console.log("initialised")
});

what's wrong with it?

Transect answered 30/1, 2015 at 13:19 Comment(0)
C
75

I'm not sure at which point you tried to initialize slickslider, but you have to do it after binding the init event.

So write your piece of code as you did and after that initialize the slider:

$('.spv-slider').on('init', function(event, slick){
    console.log("initialized")
});

And then:

$('.spv-slider').slick();
Chitarrone answered 19/3, 2015 at 11:31 Comment(1)
This doesn't seem to fire after the slider is initialised. I am trying to fire the slickNext event on init, but I get the error Cannot read property 'slickNext' of undefined... That being said, the answer is correct in that the init event must be written before the slick function.Therm

© 2022 - 2024 — McMap. All rights reserved.