LoginSignup
0
0

More than 1 year has passed since last update.

【Swiper.js】初期状態を非表示にすると挙動がおかしくなるバグへの対処法

Last updated at Posted at 2022-05-26

モーダル表示で、ボタンを押すとカルーセルが現れるように、初期状態をdisplay: none; で実装していたところ、思うように動かなかったのでその対処法

以下のようなものを作ろうとしていました
このようなものを作ろうとしていた

解決法

var mySwiper = new Swiper ('.swiper-container', {
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },
  pagination: {
    el: '.swiper-pagination'
  },
  observer: true,
  observeParents: true,
});

↓インスタンス作成時にこのコードを加えると綺麗に動くようになりました。

  observer: true,
  observeParents: true,

参考記事
https://github.com/nolimits4web/swiper/issues/1981

0
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
0
0