显示基于哪个幻灯片是旋转木马活动的隐藏内容

时间:2017-06-13 19:26:28

标签: javascript jquery twitter-bootstrap-3

我想根据哪个轮播项目处于活动状态来显示隐藏内容。即使你告诉我如何只返回活动的类元素id也会有所帮助。

1 个答案:

答案 0 :(得分:0)

根据文档,您有一些事件可以捕获轮播幻灯片http://getbootstrap.com/javascript/#carousel-events

$('#myCarousel').on('slide.bs.carousel', function () {
  // do something…
})

您可以将以下脚本放在该事件中......

var liActive = $('#carousel-example-generic').find('ol').find('li.active')[0];
console.log("li element:", liActive);

var slideActive = $(liActive).data('slide-to');
console.log('data-slide-to active:', slideActive);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">
    <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
    <li data-target="#carousel-example-generic" data-slide-to="1"></li>
    <li data-target="#carousel-example-generic" data-slide-to="2"></li>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    <div class="item">
      <img src="..." alt="...">
      <div class="carousel-caption">
        ...
      </div>
    </div>
    ...
  </div>

  <!-- Controls -->
  <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>