在Django模板的模态窗口中幻灯片显示我的图像

时间:2018-10-08 17:13:27

标签: django image templates bootstrap-modal slideshow

我希望在模式窗口中以幻灯片形式显示图像。

它工作一半时间,因为只有for循环的第一张图片到处都出现。

有人可以帮助我解决这个问题吗?

这是我的模板:

{% for a in Type_ServiceListe %}
    <p>
      <a href="#lightbox" data-toggle="modal">Open Lightbox</a>
      <div class="modal fade and carousel slide" id="lightbox">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-body">
              <ol class="carousel-indicators">
                <li data-target="#lightbox" data-slide-to="0" class="active"></li>
                <li data-target="#lightbox" data-slide-to="1"></li>
                <li data-target="#lightbox" data-slide-to="2"></li>
              </ol>
              <div class="carousel-inner">
                {% if a.image_1 %}
                <div class="item active">
                  <img src="{{ a.image_1.url }}" alt="First slide">
                </div>
                {% endif %}
                {% if a.image_2 %}
                <div class="item">
                  <img src="{{ a.image_2.url }}" alt="Second slide">
                </div>
                {% endif %}
                {% if a.image_3 %}
                <div class="item">
                  <img src="{{ a.image_3.url }}" alt="Third slide">
                </div>
                {% endif %}
              </div><!-- /.carousel-inner -->
              <a class="left carousel-control" href="#lightbox" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
              </a>
              <a class="right carousel-control" href="#lightbox" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right"></span>
              </a>
            </div><!-- /.modal-body -->
          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
      </div><!-- /.modal -->
    </p>
{% empty %}
  <p>Vide</p>
{% endfor %}


<div class="modal fade" id="imagemodal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-body">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <img src="" class="imagepreview" style="width: 100%;" >
      </div>
    </div>
  </div>
</div>




<script>
var slideIndex = 1;
showDivs(slideIndex);

function plusDivs(n) {
  showDivs(slideIndex += n);
}
function showDivs(n) {
  var i;
  var x = document.getElementsByClassName("mySlides");
  if (n > x.length) {slideIndex = 1}
  if (n < 1) {slideIndex = x.length}
  for (i = 0; i < x.length; i++) {
     x[i].style.display = "none";
  }
  x[slideIndex-1].style.display = "block";
}
</script>

0 个答案:

没有答案