我想制作无限滑块,但它不会滑动。我该如何解决? (它停留在第一张图像上,不会移动)
<div id="myCarousel" class="carousel slide slider" data-ride="carousel">
<ol class="carousel-indicators">
{% for slider in sliders%}
<li data-target="#myCarousel" data-slide-to="{{slider.id}}" class="{% if forloop.first%}active{%endif%}"></li>
{%endfor%}
</ol>
{% for slider in sliders%}
<div class="carousel-inner" role="listbox">
<div class="item{% if forloop.first %} active{% endif %}">
<img src="{{slider.image.url}}" alt="Chania">
<div class="carousel-caption capt">
<h1 >{{slider.caption}}</h1>
</div>
</div>
</div>
{%endfor%}
</div>
答案 0 :(得分:2)
下面提到的是交互式动态无限滑块的代码。
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
{% for obj in sliderview %}
{% if forloop.first %}
<li data-target="#carouselExampleIndicators" data-slide-to="{{forloop.counter0}}" class="active"></li>
{% else %}
<li data-target="#carouselExampleIndicators" data-slide-to="{{forloop.counter0}}"></li>
{% endif %}
{% endfor %}
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
{% for obj in sliderview %}
{% if forloop.first %}
<div class="carousel-item active ">
{% else %}
<div class="carousel-item ">
{% endif %}
<img class="d-block w-100 h-50" class="h-50 d-inline-block" src="{{ obj.thumbnail.url}}" alt="{{obj.title}}">
</div>
{% endfor %}
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
答案 1 :(得分:1)
没有看到任何其他内容......当您不需要时,看起来您正在重复carousel-inner
div。相反,您应该在内部包装器中添加单个items
:
<div class="carousel-inner" role="listbox">
{% for slider in sliders%}
<div class="item{% if forloop.first %} active{% endif %}">
<img src="{{slider.image.url}}" alt="Chania">
<div class="carousel-caption capt">
<h1>{{slider.caption}}</h1>
</div>
</div>
{%endfor%}
</div>