I've used slick slider recently, but I need to add a script after slick carousel has been initalised.
I have tried the below code
DEMO codepen:
Any ideas as to how I run the script after the slider has been load pletely?
//Slick Slider
$('.slider-container').slick({
infinite: true,
slidesToShow: 6,
slidesToScroll: 6
});
$('.slider-container').on('init', function (event, slick) {
alert('test');
$('.test').css('background-color', 'red'); //RUN the script after slick slider have load pletly.
});
Does anyone have any idea? or anyone can suggest a good performance and can fully customize carousel for me?
I've used slick slider recently, but I need to add a script after slick carousel has been initalised.
I have tried the below code
DEMO codepen: https://codepen.io/kelvinspaces/pen/bGEXJaG
Any ideas as to how I run the script after the slider has been load pletely?
//Slick Slider
$('.slider-container').slick({
infinite: true,
slidesToShow: 6,
slidesToScroll: 6
});
$('.slider-container').on('init', function (event, slick) {
alert('test');
$('.test').css('background-color', 'red'); //RUN the script after slick slider have load pletly.
});
Does anyone have any idea? or anyone can suggest a good performance and can fully customize carousel for me?
Share Improve this question edited Aug 2, 2020 at 12:20 ChewySalmon 6147 silver badges24 bronze badges asked Aug 2, 2020 at 11:32 KelvinKelvin 1993 silver badges15 bronze badges1 Answer
Reset to default 9Your listener needs to be placed before you initialise your slick slider. Otherwise the listener is never called because you've asked it to listen after the event has ran. That is, when you init your slick slider, your listener is not currently bound.
// Bind init event listener function
$('.slider-container').on('init', function (event, slick) {
code here...
});
// Init your slick slider
$('.slider-container').slick({
other code here...
});
It should be as above.