简体   繁体   English

Bootstrap轮播 - 在javascript中循环

[英]Bootstrap carousel - loop in javascript

I am trying to use the bootstrap carousel, but cannot really get it to work. 我正在尝试使用bootstrap carousel,但无法让它真正起作用。 I have a list with pictures I want to loop through and show in the carousel. 我有一个列表,其中包含我想要循环播放的图片并显示在旋转木马中。 I cannot show all the pictures since the "activate" (line 3 in the text below) only should be applied for the first picture (and not for the other ones in the list). 我无法显示所有图片,因为“激活”(下面文本中的第3行)只应用于第一张图片(而不是列表中的其他图片)。 This mean that I need some kind of restriction regarding the "activate". 这意味着我需要对“激活”进行某种限制。 Probably something like "only use activate for the first loop-through". 可能类似“只使用激活进行第一次循环”。 I'm not quite sure how to write that. 我不太清楚怎么写。 I'm writing in javascript (newbie) and having a really hard time incorporating it in the html file. 我正在写javascript(新手)并且很难将它合并到html文件中。

  <div class="carousel-inner">
        {% for image in images %}
          <div class="carousel-item active">
            <img src="{{ url_for('static', filename='images/' + image.image) }}" alt="{{ name }} product image" class="d-block w-100">
          </div>
        {% endfor %}
    </div>

You are using some template language here, I think Django. 你在这里使用一些模板语言,我认为Django。

You need to put class active in if block. 你需要在if块中激活class。

 {% if image in images is first %} active {% endif %}
 {% with %} {% endwith %}

I think you can use with syntax. 我认为你可以使用语法。 This example is just logic you need to follow. 这个例子只是你需要遵循的逻辑。 Just find the correct syntax. 只需找到正确的语法。 Other you do not need to change. 其他你不需要改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM