twitter-bootstrap - Bootstrap : Slide only one image among the multiple images in an item of the carousel

标签 twitter-bootstrap

我正在实现 Bootstrap Carousel 以在每个轮播项目中查看多个图像缩略图(4 个图像)。当我单击下一个或上一个控件时,它应该只从 4 个图像中滑出 1 个图像。我该如何实现这一点。

我已经试过这个例子 suggested by skelly但是当我实现它时,它只在轮播上显示一个图像,当我点击上一个/下一个控件时,除了前面的图像之外,只显示了一个图像。我需要一直显示四张图片。如果左侧的 1 张图像熄灭,则同时应从右侧插入另外 1 张图像。我另外添加了“jquery/1.11.1/jquery.min.js”和“bootstrap-3.2.0-dist/bootstrap.js”,但它没有用。

我实现的代码如下:

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="./bootstrap-3.2.0-dist/js/bootstrap.js"></script>

<script type="text/javascript">
$('#myCarousel').carousel({
interval: 4000
})

$('.carousel .item').each(function(){
var next = $(this).next();
if (!next.length) {
next = $(this).siblings(':first');
}
next.children(':first-child').clone().appendTo($(this));

for (var i=0;i<2;i++) {
next=next.next();
if (!next.length) {
  next = $(this).siblings(':first');
}

next.children(':first-child').clone().appendTo($(this));
}
});
</script>

<style type="text/css">
.carousel-inner .active.left { left: -25%; }
.carousel-inner .next        { left:  25%; }
.carousel-inner .prev    { left: -25%; }
.carousel-control        { width:  4%; }
.carousel-control.left,.carousel-control.right {margin-left:15px;background-image:none;}
</style>

</head>

<body>
<div class="col-md-12 text-center"><h3>Bootstrap 3 Multiple Slide Carousel</h3></div>
<div class="col-md-6 col-md-offset-3">
<div class="carousel slide" id="myCarousel">
<div class="carousel-inner">
<div class="item active">
  <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/e499e4/fff&amp;text=1" class="img-responsive"></a></div>
</div>
<div class="item">
  <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/e477e4/fff&amp;text=2" class="img-responsive"></a></div>
</div>
<div class="item">
  <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/eeeeee&amp;text=3" class="img-responsive"></a></div>
</div>
<div class="item">
  <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/f4f4f4&amp;text=4" class="img-responsive"></a></div>
</div>
<div class="item">
  <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/f566f5/333&amp;text=5" class="img-responsive"></a></div>
</div>
<div class="item">
  <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/f477f4/fff&amp;text=6" class="img-responsive"></a></div>
</div>
<div class="item">
  <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/eeeeee&amp;text=7" class="img-responsive"></a></div>
</div>
<div class="item">
  <div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/fcfcfc/333&amp;text=8" class="img-responsive"></a></div>
</div>
</div>
<a class="left carousel-control" href="#myCarousel" data-slide="prev"><i class="glyphicon glyphicon-chevron-left"></i></a>
 <a class="right carousel-control" href="#myCarousel" data-slide="next"><i    class="glyphicon glyphicon-chevron-right"></i></a>
 </div>
 </div>

</body>
</html>

任何建议将不胜感激。

最佳答案

我从 bootply 实现了 slider 但上一个按钮无法按预期工作。我通过添加 .carousel-inner .active.right { left: 25%; } 来修复它在 CSS 文件中。

关于twitter-bootstrap - Bootstrap : Slide only one image among the multiple images in an item of the carousel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24926919/

相关文章:

html - Bootstrap 社交媒体按钮上的居中图标

google-chrome - Bootstrap - 使用 Chrome 输入(数字)

php - 使用 PHP/MySQL 的动态 Bootstrap 选项卡

html - 来自 StringBuilder 的 Bootstrap 布局问题

html - Bootstrap Grid 在屏幕尺寸之间跳转

html - 我的 Bootstrap 网站在智能手机上出现 Body 问题

HTML Accordion 第一个无法自动关闭 CSS Bootstrap

css - CSS 样式的 iPhone 6/7 屏幕宽度实际上是多少?

twitter-bootstrap - Bootstrap 4 列排序难题

javascript - 我如何修复我的 js 代码,以便它与 Bootstrap 4 Collapse-div 一起使用?