光滑的jQuery:TypeError无法读取未定义的属性“不光滑" [英] Slick jQuery: TypeError Cannot read property 'unslick' of undefined

查看:115
本文介绍了光滑的jQuery:TypeError无法读取未定义的属性“不光滑"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经进行了ajax调用来检索数据,并且希望将图像放入Slick轮播中.

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

问题是-我已经读过-Slick只看到静态数据,所以一旦图像在html中,我就必须关闭Slick.

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.

它的编码应如下所示.

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

但是我得到了这个错误:

But I get that error:

TypeError无法读取未定义的属性'unslick'

TypeError Cannot read property 'unslick' of undefined

在我的代码中,我有2个Slick轮播. 一个是静态的,第二个是通过ajax调用接收数据时通过jQuery构造的.

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).

你有什么主意吗?

这就是我声明我的2个轮播的方式.

This is how I declare my 2 carousels.

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

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

推荐答案

好的,这是解决方案! (是的)

Ok, here is the solution! (yay)

光滑的var或类似的内容对于该轮播来说是未定义的".

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

因此,我们使用以下设置将其绑定到Slick变量:

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());

显然不需要$('your_carousel_class').slick('unslick').slick();

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

这篇关于光滑的jQuery:TypeError无法读取未定义的属性“不光滑"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆