variableWidth

更新日: 2019-12-19

スライド幅の自動計算を無効にします。

  • 初期値 : false
  • type : boolean
$('.slider').slick({
  variableWidth: false,
});

デモ

スライド幅の自動計算を無効にしています。 "有効化"ボタンを押すとスライド幅が変わります。

1

2

3

有効化
JavaScript
$(document).ready(function(){
  $('.slider').slick({
    variableWidth: false,
  });
  var variableWidth = false;
  $('.js-setoption').on('click', function() {
    variableWidth = !variableWidth;
    if (variableWidth === true) {
      $(this).text('無効化');
    } else {
      $(this).text('有効化');
    }
    $('.slider').slick('unslick');
    $('.slider').slick({
      variableWidth: variableWidth,
    });
  });
});
HTML
<div class="slider">
  <p>1</p>
  <p>2</p>
  <p>3</p>
</div>
<div class="buttons">
  <div class="button js-setoption">有効化</div>
</div>
CSS
.slick-prev:before,
.slick-next:before {
  color: #000 !important;
}

.slider p {
  font-size: 2rem;
  font-weight: bold;
  line-height: 100px;
  color: #666;
  margin: 10px;
  text-align: center;
  background-color: #e0e0e0;
}

.buttons {
  display: flex;
  justify-content: center;
}

.buttons .button {
  margin: 8px;
  border: 1px solid #000;
  color: #000;
  padding: 8px;
  text-align: center;
  width: 8em;
  transition: all 300ms ease;
}

.buttons .button:hover {
  cursor: pointer;
  background-color: #000;
  color: #fff;
  transition: all 300ms ease;
}

© 2017 Ken Wheeler Licensed under the MIT license

このコンテンツはKen Wheeler(kenwheeler)によるslickドキュメントを翻訳/改変したものです。