gpt4 book ai didi

html - Flickity 轮播图片不显示

转载 作者:太空宇宙 更新时间:2023-11-04 07:21:22 25 4
gpt4 key购买 nike

我有一个 Flickity 旋转木马,其中的所有内容都已设置好并可以正常工作,只是它只显示我拥有的最后一张图片,并在其他图片上重复显示(就好像它在它们上面一样)。我不明白为什么。

这是我的 HTML:

<div class="main-carousel" data-flickity='{ "cellAlign": "left", "contain": true }'>
<div class="carousel-cell">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/orange-tree.jpg" />
</div>
<div class="carousel-cell">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/submerged.jpg" />
</div>
<div class="carousel-cell">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/look-out.jpg" />
</div>
</div>

和 CSS:

.main-carousel {
width: 90%;
align-items: center;
margin-top: 1%;
margin-left: 5%;
height: 420px;
}

.carousel-cell {
width: 100%; /* full width */
padding-left: 10px;
height: 400px;
background: #fff;
/* center images in cells with flexbox */
display: flex;
align-items: center;
justify-content: center;
}

.carousel-cell img {
display: block;
max-height: 100%;
}

非常感谢您的帮助!

.main-carousel {
width: 90%;
align-items: center;
margin-top: 1%;
margin-left: 5%;
height: 420px;
}

.carousel-cell {
width: 100%; /* full width */
padding-left: 10px;
height: 400px;
background: #fff;
/* center images in cells with flexbox */
display: flex;
align-items: center;
justify-content: center;
}

.carousel-cell img {
display: block;
max-height: 100%;
}
<script src="https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js"></script>
<link href="https://unpkg.com/flickity@2/dist/flickity.min.css" rel="stylesheet"/>
<div class="main-carousel" data-flickity='{ "cellAlign": "left", "contain": true }'>
<div class="carousel-cell">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/orange-tree.jpg" />
</div>
<div class="carousel-cell">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/submerged.jpg" />
</div>
<div class="carousel-cell">
<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/82/look-out.jpg" />
</div>
</div>

非常感谢您的帮助!

最佳答案

有几个问题。您在加载 jQuery 之前加载 Flickity:

在文档的头部,您有:

<!-- CSS -->
<link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css">
<link rel="stylesheet" href="css/flickity.css" media="screen">
<!-- JavaScript -->
<script src="https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js"></script>
<script src="js/flickity-docs.min.js"></script>

在您的页面末尾,您有:

  <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="index.js"></script>

此外,您还加载了两次 flickity CSS 以及不必要的脚本 flickity-docs.min.js。此脚本仅适用于 flickity 网页中的文档, slider 不需要,它会引发错误。

试试这个:把它放在你的页面的头部:

  <!-- CSS -->
<link rel="stylesheet" href="https://unpkg.com/flickity@2/dist/flickity.min.css">

和底部的脚本:

 <script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script src="https://unpkg.com/flickity@2/dist/flickity.pkgd.min.js"></script>
<script src="index.js"></script>

关于html - Flickity 轮播图片不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50253298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com