gpt4 book ai didi

jquery - Bootstrap 轮播一键移动单个元素

转载 作者:行者123 更新时间:2023-12-01 06:21:52 25 4
gpt4 key购买 nike

我有这个轮播

$('#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));
}
});
.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;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<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>

https://jsfiddle.net/r5twtm22/

这工作正常。

我需要一次只移动单个图像。它移动了所有 4 个图像..

最佳答案

For some reason snippet is not showing the exact result. Please check the fiddle

<强> FIDDLE (干净且工作的版本)

$('#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));
}
});
#myCarousel .carousel-inner .active.left {
left: -33%;
}
#myCarousel .carousel-inner .active.right {
left: 33%;
}
#myCarousel .carousel-inner .next {
left: 33%;
}
#myCarousel .carousel-inner .prev {
left: -33%;
}
#myCarousel .carousel-control.left {
background-image: none;
}
#myCarousel .carousel-control.right {
background-image: none;
}
#myCarousel .carousel-inner .item {
background: white;
transition: all ease .5s;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div id="myCarousel" class="carousel slide">

<div class="carousel-inner">
<div class="item active">
<div class="col-xs-4">
<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-4">
<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-4">
<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-4">
<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-4">
<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-4">
<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>

关于jquery - Bootstrap 轮播一键移动单个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37649999/

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