gpt4 book ai didi

javascript - Bootstrap Carousel 不工作(显示页面上的所有元素)

转载 作者:太空宇宙 更新时间:2023-11-04 06:49:31 26 4
gpt4 key购买 nike

我正在尝试创建一个旋转木马。我已经创建了结构,但只希望出现五个 block ,然后在单击箭头后出现第六个 block 。我该怎么做?

我的方法:(采用from here)

img{
border: 1px solid red;
width: 100px;
height: 100px;
display: block;
}
ul{
display: inline-block;
}
li{
list-style-type: none;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="item active">
<!----------->
<!-- CTA 1 -->
<!----------->
<ul class="clearfix">
<li>
<img src=""/>
<span>Test 1</span>
</li>
</ul>
<!----------->
<!-- CTA 2 -->
<!----------->
<ul class="clearfix">
<li>
<img src=""/>
<span>Test 2</span>
</li>
</ul>
<!----------->
<!-- CTA 3 -->
<!----------->
<ul class="clearfix">
<li>
<img src=""/>
<span>Test 3</span>
</li>
</ul>
<!----------->
<!-- CTA 4 -->
<!----------->
<ul class="clearfix">
<li>
<img src=""/>
<span>Test 4</span>
</li>
</ul>
<!----------->
<!-- CTA 5 -->
<!----------->
<ul class="clearfix">
<li>
<img src=""/>
<span>Test 5</span>
</li>
</ul>
<!----------->
<!----------->

<!-- TO APPEAR AFTER CONTROL CLICK -->

<!----------->
<!-- CTA 6 -->
<!----------->
<ul class="clearfix">
<li>
<img src=""/>
<span>Test 6</span>
</li>
</ul>
</div>
</div>
<!--=====================-->
<!--== ON ARROW DISPLAY -==>
<!--=====================-->


<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>

目前,如您所见,它最初显示全部六个。不确定链接的演示和我的方法之间有什么不同(当然除了结构之外)。

最佳答案

那是因为你把所有的图像都保存在一个 <div class="item">

将它们放在单独的元素 div 中,这样:

<div class="item active">cat 1</div>
<div class="item">cat 2</div>
<div class="item">cat 3</div>
<div class="item">cat 4</div>
<div class="item">cat 5</div>
<div class="item">cat 6</div>

img {
border: 1px solid red;
width: 100px;
height: 100px;
display: block;
}

ul {
display: inline-block;
}

li {
list-style-type: none;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<div id="myCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="item active">
<!----------->
<!-- CTA 1 -->
<!----------->
<ul class="clearfix">
<li>
<img src="" />
<span>Test 1</span>
</li>
</ul>
</div>
<div class="item">
<!----------->
<!-- CTA 2 -->
<!----------->
<ul class="clearfix">
<li>
<img src="" />
<span>Test 2</span>
</li>
</ul>
</div>
<div class="item ">
<!----------->
<!-- CTA 3 -->
<!----------->
<ul class="clearfix">
<li>
<img src="" />
<span>Test 3</span>
</li>
</ul>
</div>
<div class="item ">
<!----------->
<!-- CTA 4 -->
<!----------->
<ul class="clearfix">
<li>
<img src="" />
<span>Test 4</span>
</li>
</ul>
</div>
<div class="item ">
<!----------->
<!-- CTA 5 -->
<!----------->
<ul class="clearfix">
<li>
<img src="" />
<span>Test 5</span>
</li>
</ul>
</div>
<div class="item ">
<!----------->
<!----------->

<!-- TO APPEAR AFTER CONTROL CLICK -->

<!----------->
<!-- CTA 6 -->
<!----------->
<ul class="clearfix">
<li>
<img src="" />
<span>Test 6</span>
</li>
</ul>
</div>
</div>
<!--=====================-->
<!--== ON ARROW DISPLAY -==>
<!--=====================-->


<!-- Left and right controls -->
<a class="left carousel-control" href="#myCarousel" data-slide="prev">
<span class="glyphicon glyphicon-chevron-left"></span>
<span class="sr-only">Previous</span>
</a>
<a class="right carousel-control" href="#myCarousel" data-slide="next">
<span class="glyphicon glyphicon-chevron-right"></span>
<span class="sr-only">Next</span>
</a>
</div>

关于javascript - Bootstrap Carousel 不工作(显示页面上的所有元素),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52983396/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com