LoginSignup
2
0

More than 3 years have passed since last update.

slickでレスポンシブ覚書

Posted at

①通常のSPもPCもスライドさせる、設定だけ変える

    $ele.slick({
      centerMode: true,
      slidesToShow: 1,
      variableWidth: true,
      infinite: true,
      responsive: [
        {
          breakpoint: 768,
          settings: {
            dots: true
          }
        }
      ]
    });

②SPのみスライド

slickの機能でできる

③PCのみスライド

これが厄介

そのままだと

Uncaught TypeError: Cannot read property 'add' of null
と言うエラーが出る

    if (window.innerWidth <= 768){ //PC
      $ele.not('.slick-initialized').slick({
        centerMode: true,
        slidesToShow: 1,
        variableWidth: true,
        infinite: true,
        dots: true
      });
    } else { //SP
      $('.ele.slick-initialized').slick('unslick');
    }
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0