我正在使用具有垂直过渡(且没有箭头)的Bootstrap 3传送带。可以,但是我正在寻找特定的过渡方式。
.carousel.vertical {
position: relative;
}
.carousel.vertical .carousel-inner {
height: 100%;
width: auto;
}
.carousel.vertical .carousel-inner>.item {
width: auto;
transition: 0.6s ease-in-out top;
}
.carousel.vertical .carousel-inner>.item {
transition: 0.6s ease-in-out;
}
.carousel.vertical .carousel-inner>.item.next,
.carousel.vertical .carousel-inner>.item.active.right {
transform: translate3d(0, 100%, 0);
top: 0;
}
.carousel.vertical .carousel-inner>.item.prev,
.carousel.vertical .carousel-inner>.item.active.left {
transform: translate3d(0, -100%, 0);
top: 0;
}
.carousel.vertical .carousel-inner>.item.next.left,
.carousel.vertical .carousel-inner>.item.prev.right,
.carousel.vertical .carousel-inner>.item.active {
transform: translate3d(0, 0, 0);
top: 0;
}
.carousel.vertical .carousel-inner>.active,
.carousel.vertical .carousel-inner>.next,
.carousel.vertical .carousel-inner>.prev {
display: block;
}
.carousel.vertical .carousel-inner>.active {
top: 0;
}
.carousel.vertical .carousel-inner>.next,
.carousel.vertical .carousel-inner>.prev {
position: absolute;
top: 0;
width: 100%;
}
.carousel.vertical .carousel-inner>.next {
top: 100%;
}
.carousel.vertical .carousel-inner>.prev {
top: -100%;
}
.carousel.vertical .carousel-inner>.next.left,
.carousel.vertical .carousel-inner>.prev.right {
top: 0;
}
.carousel.vertical .carousel-inner>.active.left {
top: -100%;
}
.carousel.vertical .carousel-inner>.active.right {
top: 100%;
}
.carousel.vertical .carousel-indicators {
display: inline-block;
width: auto;
padding: 0;
margin: 0;
left: auto;
right: 10px;
bottom: 2px;
z-index: 9;
font-size: 0;
}
.carousel.vertical .carousel-indicators li {
border: none;
cursor: pointer;
display: inline-block;
width: 18px;
height: 18px;
text-indent: -9999px;
background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;
}
.carousel.vertical .carousel-indicators li.active {
background-position: -528px -524px;
}
<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>
<div class="container">
<div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="https://picsum.photos/1200/300/?gravity=east" alt="">
</div>
<div class="item">
<img src="https://picsum.photos/1200/300/?gravity=south" alt="">
</div>
<div class="item">
<img src="https://picsum.photos/1200/300/?gravity=west" alt="">
</div>
</div>
<!-- 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>
</div>
</div>
还有一个 jsFiddle 。
我希望轮播的过渡方向 向上 ,无论所单击的指标是否连续。
换句话说:如果活动指标(和相应的幻灯片)是第三个,并且用户单击第二个或第一个,则过渡方向应该向上,就像活动指标是第一个,她/他在点击第二或第三指示器。
缺少什么?
答案 0 :(得分:3)
因此,我对此问题进行了很多搜索,发现了很多SO问题,没有人能够提供所需的解决方案。 但是我找到了。
这是代码段,希望对您有所帮助。
请注意,我尝试更改每个单独的规则以获得预期的结果,一旦获得所需的内容,便将它们组合在一起,并使CSS更加整洁。
// Set animation duration to 1 second
var carouselDuration = function() {
$.fn.carousel.Constructor.TRANSITION_DURATION = 1000;
}
carouselDuration();
.carousel.vertical {
position: relative;
}
.carousel.vertical .carousel-inner {
height: 100%;
width: auto;
}
.carousel.vertical .carousel-inner>.item {
width: auto;
/* set the animation duration to 1 second */
transition: 1s ease-in-out;
transform: translate3d(0, 100%, 0);
top: 0;
}
.carousel.vertical .carousel-inner>.next,
.carousel.vertical .carousel-inner>.prev,
.carousel.vertical .carousel-inner>.right {
transform: translate3d(0, 100%, 0);
top: 0;
}
.carousel.vertical .carousel-inner>.left,
.carousel.vertical .carousel-inner>.prev.right,
.carousel.vertical .carousel-inner>.next.left,
.carousel.vertical .carousel-inner>.active {
transform: translate3d(0, 0, 0);
top: 0;
}
.carousel.vertical .carousel-inner>.active.right,
.carousel.vertical .carousel-inner>.active.left {
transform: translate3d(0, -100%, 0);
top: 0;
}
.carousel.vertical .carousel-indicators {
display: inline-block;
width: auto;
padding: 0;
margin: 0;
left: auto;
right: 10px;
bottom: 2px;
z-index: 9;
font-size: 0;
}
.carousel.vertical .carousel-indicators li {
border: none;
cursor: pointer;
display: inline-block;
width: 18px;
height: 18px;
text-indent: -9999px;
background: url("https://grgs.ro/1/i/sprite.png") no-repeat -528px -502px;
}
.carousel.vertical .carousel-indicators li.active {
background-position: -528px -524px;
}
<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>
<div class="container">
<div id="myCarousel" class="carousel vertical slide" data-ride="carousel" data-interval="9000">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<img src="https://picsum.photos/1200/300/?gravity=east" alt="">
</div>
<div class="item">
<img src="https://picsum.photos/1200/300/?gravity=south" alt="">
</div>
<div class="item">
<img src="https://picsum.photos/1200/300/?gravity=west" alt="">
</div>
</div>
<!-- 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>
</div>
</div>