jquery - 旋转木马元素内的旋转木马在 Bootstrap 中不起作用

标签 jquery html css

这是我的代码。有一个父 slider 。在该 slider 的类中,每个“元素”都有另一个 slider 。外部 slider 运行良好,但嵌套 slider 在向后滑动时消失。

如果您使用 Bootstrap 运行此代码,您肯定会注意到这一点。

    <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">
        <div class="col-lg-12 col-md-12 col-sm-12 col-sx-12">
                <div id="carousel-example-generic2" class="carousel slide" data-ride="carousel">

                  <!-- Wrapper for slides -->
                  <div class="carousel-inner" role="listbox">
                    <div class="item active">
                        1
                    </div>
                    <div class="item">
                        2
                    </div>
                  </div>

                  <!-- Controls -->
                  <a class="left carousel-control" href="#carousel-example-generic2" 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-generic2" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                  </a>
                </div><!--end of item-->
        </div><!--end of col-->
    </div>
    <div class="item">
        <div class="col-lg-12 col-md-12 col-sm-12 col-sx-12">
                <div id="carousel-example-generic3" class="carousel slide" data-ride="carousel">

                  <!-- Wrapper for slides -->
                  <div class="carousel-inner" role="listbox">
                    <div class="item active">
                        3
                    </div>
                    <div class="item">
                        4
                    </div>
                  </div>

                  <!-- Controls -->
                  <a class="left carousel-control" href="#carousel-example-generic3" 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-generic3" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                  </a>
                </div><!--end of item-->
        </div><!--end of col-->
    </div>
  </div>

</div>

最佳答案

试试这段代码:

JavaScript :

$('#carousel-example-generic').carousel();
$('#carousel-example-generic2').carousel();
$('#carousel-example-generic3').carousel();

HTML:

<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>
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
    <div class="item active">
        <div class="col-lg-12 col-md-12 col-sm-12 col-sx-12">
                <div id="carousel-example-generic2" class="carousel slide" data-ride="carousel">

                  <!-- Wrapper for slides -->
                  <div class="carousel-inner" role="listbox">
                    <div class="item2 active">
                        1
                    </div>
                    <div class="item2">
                        2
                    </div>
                  </div>

                  <!-- Controls -->
                  <a class="left carousel-control" href="#carousel-example-generic2" 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-generic2" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                  </a>
                </div><!--end of item-->
        </div><!--end of col-->
    </div>
    <div class="item">
        <div class="col-lg-12 col-md-12 col-sm-12 col-sx-12">
                <div id="carousel-example-generic3" class="carousel slide" data-ride="carousel">

                  <!-- Wrapper for slides -->
                  <div class="carousel-inner" role="listbox">
                    <div class="item3 active">
                        3
                    </div>
                    <div class="item3">
                        4
                    </div>
                  </div>

                  <!-- Controls -->
                  <a class="left carousel-control" href="#carousel-example-generic3" 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-generic3" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
                    <span class="sr-only">Next</span>
                  </a>
                </div><!--end of item-->
        </div><!--end of col-->
    </div>
  </div>

</div>

关于jquery - 旋转木马元素内的旋转木马在 Bootstrap 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32965466/

相关文章:

javascript - 使用 jquery 禁用启用按钮

php 在其他 div 之前显示一个 div

html - float 列使它们高度相同 (100%)

javascript - 如何在javascript中检查文本框值和选择框值?

javascript - 表单下拉(微调器)并尝试将值更改为所选元素的值

javascript - 在 jquery 中发送正常请求(不是 ajax)

jquery - 将 box-shadow 添加到 colorbox 中?

javascript - 将选项视为选择下拉列表上的单击事件

html - 试图在缩略图悬停时显示大图像

html - 颜色:继承;不适用于 IE 或 EDGE 中的::选择