gpt4 book ai didi

javascript - Bootstrap 轮播并显示多个元素

转载 作者:行者123 更新时间:2023-11-28 06:47:14 29 4
gpt4 key购买 nike

我正在使用@paulalexandru( https://stackoverflow.com/users/3522687/paulalexandru ) 解决方案在 Bootstrap slider 上显示多个元素。不幸的是,我的 javascript 不够先进,无法显示 4 个元素(或更多或更少),而不是当前的 3 个。有人可以分解以下代码,这样我就可以理解从哪里开始理解脚本的内容一次只显示 3 个?这是 Paul 作品的一个功能正常的 JS fiddle 。 http://fiddle.jshell.net/paulalexandru/at606jpe/light/

我对 CSS 的理解还不错,但我知道轮播并不仅仅依赖于 CSS 在这里显示。我试图让它根据屏幕尺寸显示 x 个元素

最佳答案

我改变了所有:

  • 33%25%
  • col-md-4col-md-3

结果如下:

$('#myCarousel').carousel({
interval: 10000
})

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

if (next.next().length>0) {
next.next().children(':first-child').clone().appendTo($(this));
}
else {
$(this).siblings(':first').children(':first-child').clone().appendTo($(this));
}
});
.carousel-inner .active.left  { left: -25%;             }
.carousel-inner .active.right { left: 25%; }
.carousel-inner .next { left: 25% }
.carousel-inner .prev { left: -25% }
.carousel-control.left { background-image: none; }
.carousel-control.right { background-image: none; }
.carousel-inner .item { background: white; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" />

<div id="myCarousel" class="carousel slide">

<div class="carousel-inner">
<div class="item active">
<div class="col-xs-3"><a href="#"><img src="http://placehold.it/500/bbbbbb/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/CCCCCC&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/fcfcfc/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>

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

fiddle :http://fiddle.jshell.net/at606jpe/685/

关于javascript - Bootstrap 轮播并显示多个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33976695/

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