Flickity不会在轮播中呈现第二个图像

时间:2015-08-09 22:27:34

标签: javascript html css flickity

http://codepen.io/Thisisntme/pen/rVRyJE是对我网站的测试。我试图添加一个flickity轮播,由于某种原因它不会渲染div中的第二个图像。这是没有所有其他html和CSS的东西的旋转木马。 http://codepen.io/Thisisntme/pen/waOeWa

<div class="gallery js-flickity">
   <div class="gallery-cell">
      <img src="https://4c95d0ec6dcefe3d6c4d74191bd78c322c485be4.googledrive.com/host/0Bxf7lERLL3TlfjlMT28zSU9RdUFqZ2ZzWlFyWFpKMzJIbUpBelFIUnlsbTVHVUlfNVJfaXc/ART.JPG" alt="art">
   </div>
   <div class="gallery-cell">
      <img src="https://4c95d0ec6dcefe3d6c4d74191bd78c322c485be4.googledrive.com/host/0Bxf7lERLL3TlfjlMT28zSU9RdUFqZ2ZzWlFyWFpKMzJIbUpBelFIUnlsbTVHVUlfNVJfaXc/STUFF.jpg" alt="stuff">
  </div>
  <div class="gallery-cell">
  </div>
  <div class="gallery-cell"></div>
  <div class="gallery-cell"></div>
</div>

CSS:

* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.gallery {
   padding: 50px 0px 0px 0px;

}

.gallery img {
  display: block;
  width: 100%;
  height:auto;
}

Heres证明图像链接很好

art

stuff

哦,没有jQuery。

编辑:对于那些仍然关心的人,图像不再起作用了。 Google云端硬盘停止让您从他们的服务器托管。

2 个答案:

答案 0 :(得分:3)

您的.gallery-cell只需要width 100%,至少在我看来,您的img代码需要明确关闭。为了解决大小问题,我使用JS显式初始化了Flickity,而不是隐式使用HTML类。

JSFiddle:https://jsfiddle.net/3qr6hub1/2/

var flkty = new Flickity('.gallery');
* {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.gallery {
   padding: 50px 0px 0px 0px;
}

.gallery-cell {
    width: 100%;
}

.gallery img {
  width: 100%;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/flickity/1.0.0/flickity.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flickity/1.1.0/flickity.pkgd.min.js"></script>
<div class="gallery">
   <div class="gallery-cell">
       <img src="https://4c95d0ec6dcefe3d6c4d74191bd78c322c485be4.googledrive.com/host/0Bxf7lERLL3TlfjlMT28zSU9RdUFqZ2ZzWlFyWFpKMzJIbUpBelFIUnlsbTVHVUlfNVJfaXc/ART.JPG" alt="art" />
   </div>
   <div class="gallery-cell">
       <img src="https://4c95d0ec6dcefe3d6c4d74191bd78c322c485be4.googledrive.com/host/0Bxf7lERLL3TlfjlMT28zSU9RdUFqZ2ZzWlFyWFpKMzJIbUpBelFIUnlsbTVHVUlfNVJfaXc/STUFF.jpg" alt="stuff" />
  </div>
  <div class="gallery-cell">
  </div>
  <div class="gallery-cell"></div>
  <div class="gallery-cell"></div>
</div>

答案 1 :(得分:1)

好的,所以我也遇到了这个问题,在下一个Google员工通过的时候留下这个问题。每当我向旋转木马添加图像时,它都不会显示出来。

这是因为当附加单元格时,图像尚未加载。含义Flickity使此单元格没有内容,使.flickity-viewport元素的高度为0px

因此,您需要做的是确保要附加的项目被标记为 lazyLoaded 。这让Flickity知道在解析内容之前需要等待 imagesLoaded

示例:

myNewCell = '<img src="src.png" data-flickity-lazyload="src.png" />
flkty.append(myNewCell);