我正试图改变旋转木马的过渡,从左到右滑动,逐渐淡入淡出。我已经找到了多个资源,其中包括一些答案,但没有人认为对我有用,我不太明白我缺少什么。到目前为止,我看到的与我见过的例子之间的唯一区别是我在我的旋转木马和字幕中包含图像。实现我在这里提供的答案中找到的代码后:Bootstrap carousel-fade no longer working with maxcdn 3.3.bootstrap.min.css
它没有任何区别,继续滑落而不是褪色。这是我的代码,希望有人可以帮我解决问题。HTML
<!-- start -->
<div id="carousel-example-generic" class="carousel slide carousel-fade" data-ride="carousel" >
<!-- Indicators -->
<ol class="carousel-indicators">
<li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
<li data-target="#carousel-example-generic" data-slide-to="1"></li>
</ol>
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox" >
<div class="item active">
<img src="images/nightscape3.png" alt="...">
<div class="carousel-caption">
<div class="about-name-div">
<h1 >thin text<span>BOLD TEXT</span></h1>
<p class="lead">THIS IS SOME TEXT</p>
</div>
<a class="btn btn-default" href="#about" role="button" id="aboutButton">LEARN MORE ABOUT US</a>
</div>
</div>
<div class="item">
<img src="images/tech.jpg" alt="...">
<div class="carousel-caption">
</div>
</div>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#carousel-example-generic" 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="#carousel-example-generic" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!-- end -->
CSS
.carousel-fade .carousel-inner .item {
opacity: 0;
transition-property: opacity;
}
.carousel-fade .carousel-inner .active {
opacity: 1;
}
.carousel-fade .carousel-inner .active.left,
.carousel-fade .carousel-inner .active.right {
left: 0;
opacity: 0;
z-index: 1;
}
.carousel-fade .carousel-inner .next.left,
.carousel-fade .carousel-inner .prev.right {
opacity: 1;
}
.carousel-fade .carousel-control {
z-index: 2;
}
/*
WHAT IS NEW IN 3.3: "Added transforms to improve carousel performance in modern browsers."
now override the 3.3 new styles for modern browsers & apply opacity
*/
@media all and (transform-3d), (-webkit-transform-3d) {
.carousel-fade .carousel-inner > .item.next,
.carousel-fade .carousel-inner > .item.active.right {
opacity: 0;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.carousel-fade .carousel-inner > .item.prev,
.carousel-fade .carousel-inner > .item.active.left {
opacity: 0;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.carousel-fade .carousel-inner > .item.next.left,
.carousel-fade .carousel-inner > .item.prev.right,
.carousel-fade .carousel-inner > .item.active {
opacity: 1;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
答案 0 :(得分:0)
我认为您还应该考虑position
的{{1}}(left
}。我还在.item
添加了一个额外的类(.anim
),而不是<div class="carousel-inner" role="listbox" >
类的包装器。
然后你应该可以使用如下所示的CSS代码:
.carousel
以上适用于v3.2。演示:http://www.bootply.com/7scRiubjja
自v3.3起,轮播的Less / CSS代码已更改。转换和转换包含在@-webkit-keyframes fadeIn {
0% {opacity: 0;}
100% {opacity: 1;}
}
@keyframes fadeIn {
0% {opacity: 0;}
100% {opacity: 1;}
}
@-webkit-keyframes fadeOut {
0% {opacity: 1;}
100% {opacity: 0;}
}
@keyframes fadeOut {
0% {opacity: 1;}
100% {opacity: 0;}
}
.carousel-inner.anim > .item {
left: 0;
}
.carousel-inner.anim > .next,
.carousel-inner.anim > .prev {
position: absolute;
top: 0;
width: 100%;
}
.carousel-inner.anim > .next.left {
-webkit-backface-visibility: visible;
backface-visibility: visible;
-webkit-animation-name: fadeIn;
animation-name: fadeIn;
-webkit-animation-duration:0.6s;
animation-duration:0.6s;
}
.carousel-inner.anim > .prev.right {
-webkit-animation-name: fadeIn;
animation-name: fadeIn;
-webkit-animation-duration:0.6s;
animation-duration:0.6s;
}
.carousel-inner.anim > .active.left {
-webkit-animation-name: fadeOut;
animation-name: fadeOut;
-webkit-animation-duration:0.6s;
animation-duration:0.6s;
}
.carousel-inner.anim > .active.right {
-webkit-animation-name: fadeOut;
animation-name: fadeOut;
-webkit-animation-duration:0.6s;
animation-duration:0.6s;
}
要将上述内容用于v3.3 +,您应该使用上述媒体查询重写代码,或重置原始代码。可以使用以下CSS代码重置原始代码:
@media all and (transform-3d), (-webkit-transform-3d) {}
演示:http://www.bootply.com/PHBjOgJlIt
根据此处给出的答案Bootstrap carousel-fade no longer working with maxcdn 3.3.bootstrap.min.css,您还可以重置:
.carousel-inner > .item {
-webkit-transition: none;
transition: none;
}
@media all and (transform-3d), (-webkit-transform-3d) {
.carousel-inner > .item {
-webkit-transition: none;
transition: none;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-perspective: 1000;
perspective: 1000;
}
.carousel-inner > .item.next,
.carousel-inner > .item.active.right {
-webkit-transform: none;
-ms-transform: none;
transform: none;
left: 0;
}
.carousel-inner > .item.prev,
.carousel-inner > .item.active.left {
-webkit-transform: none;
-ms-transform: none;
transform: none;
left: 0;
}
.carousel-inner > .item.next.left,
.carousel-inner > .item.prev.right,
.carousel-inner > .item.active {
-webkit-transform: none;
-ms-transform: none;
transform: none;
left: 0;
}
}