【发布时间】:2018-09-19 05:27:13
【问题描述】:
尝试使用引导 4 轮播功能来执行此操作(下图是 bootstrap 3 variant)
我尝试将其转换为引导程序 4。我对它所做的是通过 html 上的 bootstrap 3 → to bootstrap 4 html conversion tool 运行它,并调整对 CDN 中引导程序 JS 和 CSS 文件的引用。我还用颜色更改了图像引用,以便更容易区分我想要显示的图像。
下面是代码,它没有在一张幻灯片上显示所有 4 张图片
$(document).ready(function() {
$('#Carousel').carousel({
interval: 5000
})
});
body{padding-top:20px;}
.carousel {
margin-bottom: 0;
padding: 0 40px 30px 40px;
}
/* The controlsy */
.carousel-control {
left: -12px;
height: 40px;
width: 40px;
background: none repeat scroll 0 0 #222222;
border: 4px solid #FFFFFF;
border-radius: 23px 23px 23px 23px;
margin-top: 90px;
}
.carousel-control.right {
right: -12px;
}
/* The indicators */
.carousel-indicators {
right: 50%;
top: auto;
bottom: -10px;
margin-right: -19px;
}
/* The colour of the indicators */
.carousel-indicators li {
background: #cecece;
}
.carousel-indicators .active {
background: #428bca;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<div class="col-lg-12">
<div id="Carousel" class="carousel slide">
<ol class="carousel-indicators">
<li data-target="#Carousel" data-slide-to="0" class="active"></li>
<li data-target="#Carousel" data-slide-to="1"></li>
<li data-target="#Carousel" data-slide-to="2"></li>
</ol>
<!-- Carousel items -->
<div class="carousel-inner">
<div class="item active carousel-item">
<div class="row">
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250/0ff" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250/0ff" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250/0ff" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250/0ff" alt="Image" style="max-width:100%;"></a>
</div>
</div>
<!--.row-->
</div>
<!--.item-->
<div class="item carousel-item">
<div class="row">
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250/00f" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250/00f" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250/00f" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250/00f" alt="Image" style="max-width:100%;"></a>
</div>
</div>
<!--.row-->
</div>
<!--.item-->
<div class="item carousel-item">
<div class="row">
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a>
</div>
<div class="col-lg-3"><a href="#" class="thumbnail"><img src="http://placehold.it/250x250" alt="Image" style="max-width:100%;"></a>
</div>
</div>
<!--.row-->
</div>
<!--.item-->
</div>
<!--.carousel-inner--><a data-slide="prev" href="#Carousel" class="left carousel-control">‹</a>
<a data-slide="next" href="#Carousel" class="right carousel-control">›</a>
</div>
<!--.Carousel-->
</div>
</div>
</div>
<!--.container-->
【问题讨论】:
-
"寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定问题或错误以及在问题本身中重现它所需的最短代码。没有明确的问题陈述对其他读者没有用处。”
-
@Zimsystem 你真的看过类似的stackoverflow帖子吗?它们在功能上不一样。该问题对源代码有参考。我已经在互联网上搜索了几个小时的解决方案,这是我唯一知道的。如果您不将其保留为副本,我将不胜感激,因为这样做会损害 stackoverflow。
-
编辑问题以显示您到目前为止所尝试的内容。代码应该在问题中。然后解释它为什么不与同一主题的许多其他问题重复。
标签: html css twitter-bootstrap twitter-bootstrap-3 bootstrap-4