2

在 Twitter Bootstrap Carousel Slide 中,需要一个名为“active”的类来设置所有幻灯片首先使用哪个图像,然后初始化循环。但是,如果我的对象(我想在幻灯片中显示)处于循环中,我该如何设置这个类?

<div id="myCarousel" class="carousel slide img-polaroid">
  <div class="carousel-inner">

    {% for slide in slides_list %}
    <div class="item"> <!-- Here goes the class="active" -->
      <img src="{{slide.imagem.url}}" alt="{{slide.imagem.titulo}}" />
      <div class="carousel-caption slider">
        <h2>{{slide.titulo}}</h2>
        <p>{{slide.mensagem}}</p>
      </div><!--/carousel-caption-->
    </div><!--/item-->
    {% endfor %}

  </div><!--/carousel-inner-->

  <a class="carousel-control left" href="#myCarousel" data-slide="prev">&lsaquo;</a>
  <a class="carousel-control right" href="#myCarousel" data-slide="next">&rsaquo;</a>

</div><!--/myCarousel-->

提前致谢。

4

1 回答 1

5
{% for slide in slides_list %}
<div class="item{% if forloop.first %} active{% endif %}">
  <img src="{{slide.imagem.url}}" alt="{{slide.imagem.titulo}}" />
  <div class="carousel-caption slider">
    <h2>{{slide.titulo}}</h2>
    <p>{{slide.mensagem}}</p>
  </div><!--/carousel-caption-->
</div><!--/item-->
{% endfor %}

for标签和变量forloopdocs

于 2013-04-07T20:55:35.087 回答