javascript - 为什么我的轮播最后有一个空元素?

标签 javascript html css twig owl-carousel

我使用 owl-carousel 在我的页面上有两个轮播。两者都显示一个空的最后一项。我是初学者,我不知道如何解决这个问题。有人可以帮助我吗?

我正在使用 twig 循环遍历我的 php 数组。

<section id='noticia-carousel' class='pt-0'>
        <div class='container main-container'>
            <div class='owl-carousel owl-theme'>
                {% for noticia in noticias_principais %}
                <div class='box'>
                    <img src='{{noticia.imagem_capa}}' alt='Imagem referente à notícia {{noticia.titulo | striptags}}'>
                    <div class='titulo'>
                        <h4><a href='noticia/{{noticia.id}}'> {{noticia.titulo | striptags}} </a></h4>
                    </div>
                </div>
                {% endfor %}

                <div class="owl-controls">
                    <div class="owl-nav">
                    </div>
                </div>
            </div>

            <div class='text-center'>
                <button class='btn btn-secondary' onclick="window.location.href='/noticias'">Todas
                    as Notícias </button>
            </div>
        </div>
    </section>
$('#noticia-carousel .owl-carousel').owlCarousel({
        items: 2,
        dots: false,
        nav: true,
        navText: ['<i class="fa fa-angle-left" aria-hidden="true"></i>', '<i class="fa fa-angle-right" aria-hidden="true"></i>'],
        animateOut: 'fadeOut',
        autoplay: true,
        loop: true,
        autoplayTimeout: 4000,
        autoplayHoverPause: true,
        responsiveClass: true,
        responsive: {
            0: {
                items: 1,
                nav: false
            },
            600: {
                items: 1,
                nav: false
            },
            1000: {
                items: 2
            },
            1300: {
                items: 2
            }
        }

    });

这是它现在的样子:https://educacao.ouropreto.mg.gov.br/ 效果很好,但最后一项是空的。我希望它自动播放并循环播放。

最佳答案

在你的 {% for %} 循环之后的这个 HTML 已经成为你轮播中的一个元素,因为它是 .owl-carousel 的 child >:

<div class="owl-controls">
  <div class="owl-nav"></div>
</div>

去掉它,轮播就没有多余的空间了。

关于javascript - 为什么我的轮播最后有一个空元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55362965/

相关文章:

用于查找最近三年内日期的 JavaScript 语法

javascript - 是否可以计算 html 页面的空白区域?

css - 如何在带有渐变的 CSS 中制作类型为 "double"的边框?

javascript - 覆盖一个 div 并让它在单击链接后消失

css - 如何使用 IONIC 框架在中心或右侧对齐按钮?

javascript - 巨大 float 的国际格式

Javascript:简单的加法程序不起作用

javascript - Azure 服务总线队列发送消息速度缓慢

html - 我可以覆盖样式吗?

html - 将 2 个 50% 宽度的输入元素排成一行,理解框大小