Slick-carousel error unslick不是一个功能

时间:2018-05-22 12:22:32

标签: jquery slick.js

如您所见,顶部有4个街区4,下方有4个街区。

我需要滑块适用于移动版。就像there

一样

此外,如果您仔细查看此链接,您应该会看到此代码无法在onload中工作。

我将对此代码进行一些更改,但它必须正常工作,但确实如此。我在控制台中收到了一堆错误。

错误:无法读取属性' unslick'未定义的

我试图改变

Select ui.ID,sp.PlanName, sp.PlanIsValid 
from Usersinfo ui 
left join SubscriptionPlan sp on ui.ID = sp.UserID 

 $(".container-slick").unslick("unslick");

但它没有用。

请帮忙。

这是我的codepen



$(".container-slick").slick({
   settings:"unslick"
});

$(window).on('load', function(){
    if($(window).width() < 768){
     $('.container-slick').slick({
          centerMode: true,
          infinite: true,
          prevArrow: false,
          nextArrow: false,
          speed: 200,
          slidesToShow: 1
        });
    }
    else{
      $(".container-slick").slick("unslick");
    }
  });
$(window).on('resize', function(){
    if($(window).width() < 768){
     $('.container-slick').slick({
          centerMode: true,
          infinite: true,
          prevArrow: false,
          nextArrow: false,
          speed: 200,
          slidesToShow: 1
        });
    }
    else{
      $(".container-slick").unslick("unslick");
    }
  });
  
&#13;
.projects_block {
    margin-bottom: 2%;
    display: flex;
    font-family: 'montserrat';
    flex-wrap: wrap;
}
.project_block {
    width: 23%;
    height:100px;
}
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

-->As on Window Load if width is less than 768 px then only we are applying slick js no need to unslick it because it will fire only width is less than 768px 
--> Also on resize Jquery There is an error of $(".container-slick").unslick("unslick"); 
--> So your new script will be like this

<script type="text/javascript">

    $(window).on('load', function(){
    if($(window).width() < 768){
     $('.container-slick').slick({
          centerMode: true,
          infinite: true,
          prevArrow: false,
          nextArrow: false,
          speed: 200,
          slidesToShow: 1
        });
    }
    else{
    }
  });
$(window).on('resize', function(){
    if($(window).width() < 768){
     $('.container-slick').slick({
          centerMode: true,
          infinite: true,
          prevArrow: false,
          nextArrow: false,
          speed: 200,
          slidesToShow: 1
        });
    }
    else{
      $(".container-slick").slick("unslick");
    }
  });

</script>