Fancybox + Flickity。 iOS方向问题

Fancybox + Flickity. iOS orientation issue

在 Fancybox 模式中 window 我有 Flickity 轮播。在 iPad 上,当我更改方向时,Flickity 停止正常工作。 flickity-viewport 显示为 0px。桌面 window 调整大小没有问题。不确定 iPad 方向发生变化时如何更新 Flickity。

https://jsfiddle.net/2zb5qesa/13/embedded/result/

$(document).ready(function() {
  $('.carousel-container').each( function( i, container ) {
    var $container = $( container );
    // main Flickity
    var $carouselMain = $container.find('.carousel-main').flickity({
      imagesLoaded: true,
      percentPosition: false,
      pageDots: false,
      adaptiveHeight: true
    });
    // nav Flickity
    $container.find('.carousel-nav').flickity({
      asNavFor: $carouselMain[0],
      contain: true,
      pageDots: false,
      groupCells: true,
      adaptiveHeight: true,
      prevNextButtons: false
    });
  });

  $("[data-fancybox]").fancybox({
    idleTime : false,
    smallBtn: false, 
    buttons : [
      'close'
    ],
    touch : {
       vertical : false,
       momentum : false
    },
    wheel : false,
    afterShow: function( instance, slide ){
      slide.$slide.find('.carousel-main').flickity('resize');
      slide.$slide.find('.carousel-nav').flickity('resize');
    }
  });
});
.carousel {
  background: #FAFAFA;
  margin-bottom: 40px;
}

.carousel-cell {
  width: 100%;
  height: 200px;
  margin-right: 10px;
  background: #8C8;
  border-radius: 5px;
  counter-increment: carousel-cell;
}

/* cell number */
.carousel-cell:before {
  display: block;
  text-align: center;
  content: counter(carousel-cell);
  line-height: 200px;
  font-size: 80px;
  color: white;
}

.carousel-nav .carousel-cell {
  height: 80px;
  width: 100px;
}

.carousel-nav .carousel-cell:before {
  font-size: 50px;
  line-height: 80px;
}

.carousel-nav .carousel-cell.is-nav-selected {
  background: #ED2;
}

.modal-window {
 width: 985px;
 padding: 0;
 background: none;
}
.modal-window-inner {
 width: 980px;
 padding: 40px;
 position: relative;
 background: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://unpkg.com/flickity@2.1.2/dist/flickity.pkgd.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.3.5/jquery.fancybox.min.css" rel="stylesheet"/>
<link href="https://unpkg.com/flickity@2.1.2/dist/flickity.css" rel="stylesheet"/>
<a data-src="#p1" href="javascript:;" data-fancybox="gallery">MODAL 1</a>
<a data-src="#p2" href="javascript:;" data-fancybox="gallery">MODAL 2</a>

<div style="display: none;" id="p1" class="modal-window">
  <div class="modal-window-inner">
    <div class="carousel-container">
      <div class="carousel carousel-main">
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
      </div>
      <!-- /.carousel-main -->
      <div class="carousel carousel-nav">
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
      </div>
      <!-- /.carousel-nav -->
    </div>
    <!-- /.carousel-container -->
  </div>
  <!-- /.modal-window-inner -->
</div>
<!-- /.modal-window -->

<div style="display: none;" id="p2" class="modal-window">
  <div class="modal-window-inner">
    <div class="carousel-container">
      <div class="carousel carousel-main">
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
      </div>
      <!-- /.carousel-main -->
      <div class="carousel carousel-nav">
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
        <div class="carousel-cell"></div>
      </div>
      <!-- /.carousel-nav -->
    </div>
    <!-- /.carousel-container -->
  </div>
  <!-- /.modal-window-inner -->
</div>
<!-- /.modal-window -->

我认为这是因为 fancybox 在设备方向更改事件中暂时隐藏了内容,也许尝试为 fancybox 添加这个,看看是否有帮助:

onUpdate : function( instance, slide ) {
    slide.$slide.find('.carousel-main').flickity('resize');
    slide.$slide.find('.carousel-nav').flickity('resize');
}