Bootstrap 4轮播不工作?
Posted
技术标签:
【中文标题】Bootstrap 4轮播不工作?【英文标题】:Bootstrap 4 carousel not working? 【发布时间】:2018-07-27 01:31:43 【问题描述】:我有以下 BS4 Carousel 代码,(使用本教程 https://www.youtube.com/watch?v=n8ItscKLf7s&list=PLRtjMdoYXLf47brThg9-nTj8HSq8cQ0ND&index=53 制作),但是代码不起作用,显示第一张图像但我不知道是什么原因 carousel 不受控制,它没有无论如何,请转到下一张图片。有什么可能的解决方案?
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12">
<br />
<div id="carousel-example-generic" class="carousel-slide" data-ride="carousel">
<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>
<div class="carousel-inner" role="listbox">
<div class="carousel-item-active">
<img src="images/1.jpeg" >
</div>
<div class="carousel-item">
<img src="images/2.jpeg" >
</div>
<div class="carousel-item">
<img src="images/3.jpeg" >
</div>
</div>
<a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
<span class="icon-prev" 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="icon-next" aria-hidden="true"></span>
<span class="sr-only"> Next </span>
</a>
</div>
</div>
</div>
</div>
【问题讨论】:
你可以试试这个顺便说一句w3schools.com/bootstrap4/bootstrap_carousel.asp 您应该经常查看文档!如您在这种情况下所见,视频可能已过时。 getbootstrap.com 是官方文档的网址。 @Shahrukh Nasir 回答您使用 bootstrap 3.3.7 接受,不确定您在寻找哪个版本。 【参考方案1】:完美运行
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<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>
</head>
<body>
<div class="container">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
<li data-target="#myCarousel" data-slide-to="1"></li>
<li data-target="#myCarousel" data-slide-to="2"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="https://www.w3schools.com/bootstrap/ny.jpg" style="width:100%;">
</div>
<div class="item">
<img src="https://www.w3schools.com/bootstrap/chicago.jpg" style="width:100%;">
</div>
<div class="item">
<img src="https://www.w3schools.com/bootstrap/newyork.jpg" style="width:100%;">
</div>
</div>
<!-- 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>
</body>
</html>
【讨论】:
【参考方案2】:小错误。 class="carousel-item-active"
应该是 class="carousel-item active"
。它不是一个单一的类。您已将 active
类与 carousel-item
类组合在一起。那是错误。
<div class="carousel-item-active">
<img src="images/1.jpeg" >
</div>
应该改为
<div class="carousel-item active">
<img src="images/1.jpeg" >
</div>
【讨论】:
以上是关于Bootstrap 4轮播不工作?的主要内容,如果未能解决你的问题,请参考以下文章
bootstrap 轮播craousel 采坑之(修改默认鼠标浮动轮播不停止)