javascript - Slick jQuery: TypeError Cannot read property 'unslick' of undefined - Stack Overflow

admin2025-03-13  2

I've done an ajax call to retrieve data and I want to put the images in a Slick carousel.

The problem is - I've read - Slick only see static data, so I've to turn-off turn-on Slick once images are in html.

It should be coded as here below.

$('.slick-media').slick('unslick').slick('reinit');

But I get that error:

TypeError Cannot read property 'unslick' of undefined

In my code I have 2 Slick carousels. One is static, the second one is construced via jQuery when data is received by ajax call.

If I try to unslick the static carousel, then it works. But I'm not able to unslick the second carousel, which is dynamically built (I get the error).

Do you have any idea?

This is how I declare my 2 carousels.

$(document).ready(function(){
      $('.carousel').slick({
        //properties
      });

      $('.product_carousel').slick({  
        //properties
      });
    });

I've done an ajax call to retrieve data and I want to put the images in a Slick carousel.

The problem is - I've read - Slick only see static data, so I've to turn-off turn-on Slick once images are in html.

It should be coded as here below.

$('.slick-media').slick('unslick').slick('reinit');

But I get that error:

TypeError Cannot read property 'unslick' of undefined

In my code I have 2 Slick carousels. One is static, the second one is construced via jQuery when data is received by ajax call.

If I try to unslick the static carousel, then it works. But I'm not able to unslick the second carousel, which is dynamically built (I get the error).

Do you have any idea?

This is how I declare my 2 carousels.

$(document).ready(function(){
      $('.carousel').slick({
        //properties
      });

      $('.product_carousel').slick({  
        //properties
      });
    });
Share Improve this question edited Jan 6, 2017 at 10:47 br3t 1,6582 gold badges21 silver badges28 bronze badges asked Apr 25, 2016 at 23:19 FrancescoNFrancescoN 2,18612 gold badges36 silver badges48 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Ok, here is the solution! (yay)

Slick var or something similar was 'undefined' for that carousel.

So we bind it to the Slick var with our settings:

function getSliderSettings() {
      return {
        dots: true,
        arrows: false,
        slidesToShow: 1,
        cssEase: 'ease',
        variableWidth: false,
        speed: 800,
        fade: true,
        cssEase: 'linear'
      }
}

$('.product_carousel').slick(getSliderSettings());

Apparently there's no need to do $('your_carousel_class').slick('unslick').slick();

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1741854774a184024.html

最新回复(0)