这是我的carousal的html代码
<section id="showcase">
<div id="myCarousel" class="carousel slide" data-ride="carousel">
<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 class="carousel-inner">
<div class="carousel-item carousel-image-1 active">
<div class="container">
<div class="carousel-caption d-none d-sm-block text-right mb-5">
<h1 class="display-3">Heading One</h1>
<p class="lead">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus illum commodi enim consequatur nesciunt voluptatum perspiciatis sint. Nemo, modi nulla.</p>
<a href="#" class="btn btn-danger btn-lg">Sign Up Now</a>
</div>
</div>
</div>
<div class="carousel-item carousel-image-2">
<div class="container">
<div class="carousel-caption d-none d-sm-block mb-5">
<h1 class="display-3">Heading Two</h1>
<p class="lead">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus illum commodi enim consequatur nesciunt voluptatum perspiciatis sint. Nemo, modi nulla.</p>
<a href="#" class="btn btn-primary btn-lg">Learn More</a>
</div>
</div>
</div>
<div class="carousel-item carousel-image-3">
<div class="container">
<div class="carousel-caption d-none d-sm-block text-right mb-5">
<h1 class="display-3">Heading Three</h1>
<p class="lead">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Natus illum commodi enim consequatur nesciunt voluptatum perspiciatis sint. Nemo, modi nulla.</p>
<a href="#" class="btn btn-success btn-lg">Learn More</a>
</div>
</div>
</div>
</div>
<a href="#myCarousel" data-slide="prev" class="carousel-control-prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a href="#myCarousel" data-slide="next" class="carousel-control-next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
我想为此幻灯片设置淡入效果。任何人都可以帮助我制作我的CSS代码。 我发现了一些像这样的旋转木马的CSS代码。
但它无法正常工作。
.carousel-fade .carousel-inner .item {
-webkit-transition-property: opacity;
transition-property: opacity;
}
.carousel-fade .carousel-inner .item,
.carousel-fade .carousel-inner .active.left,
.carousel-fade .carousel-inner .active.right {
opacity: 0;
}
.carousel-fade .carousel-inner .active,
.carousel-fade .carousel-inner .next.left,
.carousel-fade .carousel-inner .prev.right {
opacity: 1;
}
.carousel-fade .carousel-inner .next,
.carousel-fade .carousel-inner .prev,
.carousel-fade .carousel-inner .active.left,
.carousel-fade .carousel-inner .active.right {
left: 0;
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
.carousel-fade .carousel-control {
z-index: 2;
}
html,
body,
.carousel,
.carousel-inner,
.carousel-inner .item
{
height: 100%;
}
.item:nth-child(1) {
background: url("../img/img2.jpeg");
background-size: cover;
}
}
.item:nth-child(2) {
background: url("../img/img2.jpeg");
background-size: cover;
}
}
.item:nth-child(3) {
background: url("../img/img2.jpeg");
background-size: cover;
}
}
我想为我的bootstrap carousal编辑这个css代码。
如果有人知道另一种淡入效果的方法,请帮助我。
答案 0 :(得分:0)
试试这个。希望它对你有所帮助
.carousel .item {
-webkit-transition: opacity 0.5s ease-in-out;
-moz-transition: opacity 0.5s ease-in-out;
-ms-transition: opacity 0.5s ease-in-out;
-o-transition: opacity 0.5s ease-in-out;
transition: opacity 0.5s ease-in-out;
opacity:0;
}
.carousel .active.item {
opacity:1;
}
.carousel.carousel-fade .active.left,
.carousel.carousel-fade .active.right {
left: 0;
z-index: 2;
opacity: 0;
filter: alpha(opacity=0);
}
.carousel.carousel-fade .next,
.carousel.carousel-fade .prev {
left: 0;
z-index: 1;
}
.carousel.carousel-fade .carousel-control {
z-index: 3;
}
答案 1 :(得分:0)
这个对我有用。只需在您的样式区域中添加此CSS代码即可。
.carousel-fade .carousel-inner > .item {
transition-property: opacity;
}
.carousel-fade .carousel-inner > .item,
.carousel-fade .carousel-inner > .item.active.left {
opacity: 0;
}
.carousel-fade .carousel-inner > .item.active,
.carousel-fade .carousel-inner > .item.next.left {
opacity: 1;
}
.carousel-fade .carousel-inner > .next,
.carousel-fade .carousel-inner > .prev,
.carousel-fade .carousel-inner > .active.left,
.carousel-fade .carousel-inner > .active.right {
left: 0;
}
.carousel-fade .carousel-inner > .item.next,
.carousel-fade .carousel-inner > .item.active.right,
.carousel-fade .carousel-inner > .item.prev,
.carousel-fade .carousel-inner > .item.active.left {
transform: translate3d(0, 0, 0);
}