我正在使用最新的Bootstrap Carousel,需要在幻灯片之间缓慢(大约5s)褪色.我已经看了很多例子,并试图实现这个
one.问题是幻灯片之间的淡入太快(不到一秒钟).如何将其更改为更长的淡入淡出?
这是我的代码:
<div class="carousel slide" id="slideshow-carousel-1" data-ride="carousel"> <div class="carousel-inner" role="listBox"> <!-- Slide 1 --> <div class="item item-1 slide-image active"> <img class="img-responsive bg-item parallax" data-speed="1" data-width="1980" data-height="1485" src="~/images/slideshow/bottle1.png" alt="Slide 1 Background"> <div class="carousel-caption"> <h1 class="title">Caption 1</h1> </div> </div> <!-- End Slide 1 --> <!-- Slide 2 --> <div class="item item-2 slide-image"> <img class="img-responsive bg-item parallax" data-speed="1" data-width="1980" data-height="1485" src="~/images/slideshow/bottle2.jpg" alt="Slide 2 Background"> <div class="carousel-caption"> <h1 class="title">Or Bottle!</h1> </div> </div> <!-- End Slide 2 --> </div> </div>
这是CSS:
.carousel-inner > .item { opacity: 0; top: 0; left: 0; width: 100%; display: block; position: absolute; z-index: 0; -webkit-transition: opacity 5s ease; -o-transition: opacity 5s ease; transition: opacity 5s ease; -webkit-transform: translate3d(0,0) !important; transform: translate3d(0,0) !important; } .carousel-inner > .item:first-of-type { position: relative; } .carousel-inner > .active { opacity: 1; z-index: 3; } .carousel-inner > .next.left,.carousel-inner > .prev.right { -webkit-transition: opacity 0.6s ease-in-out; -o-transition: opacity 0.6s ease-in-out; transition: opacity 0.6s ease-in-out; opacity: 1; left: 0; z-index: 2; } .carousel-inner > .active.left,.carousel-inner > .active.right { z-index: 1; } .carousel-control { z-index: 4; }
解决方法
正如我已故的伟大的计算机科学教授曾经说过的那样,解决方案并非易事.
Slick Carousel(Bootstrap Carousel的衍生物)在body标签上使用class =“sld-transition-2”(三个可用类别之一)来设置轮播的转换.这与我试图设置的淡入淡出过渡相撞.所以它被删除了.
@transportedman从这个Stackoverflow answer提供的CSS3解决方案就是硬件.我根据我们的要求对它进行了一些修改,并将它放在最后一个要为网站加载的CSS文件中(覆盖之前的所有内容):
/* inspired from http://codepen.io/Rowno/pen/Afykb https://stackoverflow.com/questions/26770055/bootstrap-carousel-fade-no-longer-working-with-maxcdn-3-3-bootstrap-min-css */ .carousel-fade .carousel-inner .item { opacity: 0; transition-property: opacity; transition-duration: 4s; transition-timing-function:linear; } .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); transform: translate3d(0,0); } .carousel-fade .carousel-inner > .item.prev,.carousel-fade .carousel-inner > .item.active.left { opacity: 0; -webkit-transform: translate3d(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); } }
最后但并非最不重要的是,修改了轮播DIV标签以具有data-interval属性,该属性大于上述CSS3中设置的transition-duration:
<div class="carousel slide carousel-fade" id="slideshow-carousel-1" data-ride="carousel" data-interval="7000"> ..... </div>
希望这可以帮助遇到类似问题的其他人.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。