我正在尝试为使用Bootstrap和AngularJS创建的网站创建淡入淡出过渡轮播。我已经创建了效果,但我不断在每张幻灯片之间将此闪光灯变为白色,而不是在上一张图像上显示淡化效果。你现在可以在这里看到它的一个例子(直到问题得到解答或我修复它):
http://development.artlyticalmedia.com/portfolio
我正在使用UI Bootstrap,因为它使Bootstrap与AngularJS很好用,因为我的html看起来像这样,因此已经使得大多数解决方案都不准确:
<div class="container-fluid text-center" ng-controller="PortfolioCtrl" id="portfolio">
<carousel interval="interval" class="carousel-fade">
<slide ng-repeat="slide in slides" active="slide.active">
<img ng-src="{{slide.image}}" alt="{{slide.alt}}">
</slide>
</carousel>
</div>
请注意,标准Bootstrap轮播中不存在<carousel>
元素;我相信这是一个<div class="carousel">
。我的SCSS应该给出正确的效果,如下所示:
.carousel-fade {
.carousel-inner {
.item {
transition-property: opacity;
transition-duration: 1s;
opacity: 0;
}
.active {
opacity: 1;
}
.active.left,
.active.right {
left: 0;
opacity: 0;
z-index: 1;
}
.next.left,
.prev.right {
opacity: 1;
}
}
.carousel-control {
z-index: 2;
}
}
我的Javascript非常标准,除了我禁用$animate
,因为这是我之前必须实现的修复。无论如何它在这里:
angular.module('comartlyticalmediawwwApp')
.controller('PortfolioCtrl', function ($scope, $animate) {
$scope.interval = 3000;
$animate.enabled(false);
$scope.animate = null;
$scope.animateGlobal = true;
$scope.slides = [
{
image: 'images/portfolio/websites/3dsailing-Home.png',
alt: 'plan'
},
{
image: 'images/portfolio/websites/3dsailing-SailCoachPro.png',
alt: 'act'
},
{
image: 'images/portfolio/websites/3dsailing-3D-Printing.png',
alt: 'done'
},
{
image: 'images/portfolio/websites/Glass-Planner-Home.png',
alt: 'done'
},
{
image: 'images/portfolio/websites/Glass-Planner-PlanActDone.png',
alt: 'done'
},
{
image: 'images/portfolio/websites/Glass-Planner-Tutorials.png',
alt: 'done'
}];
});
答案 0 :(得分:8)
在遇到这个问题几个小时之后我终于发现了transform:translate3d()是我们都遇到这个问题的原因。
尝试使用此代码:
.carousel-fade {
.carousel-inner {
.item {
opacity: 0;
-webkit-transition-property: opacity;
transition-property: opacity;
}
.active {
opacity: 1;
}
.active.left,
.active.right {
left: 0;
opacity: 0;
z-index: 1;
}
.next.left,
.prev.right {
opacity: 1;
}
}
.carousel-control {
z-index: 2;
}
}
@media all and (transform-3d), (-webkit-transform-3d) {
.carousel-inner > .item.next,
.carousel-inner > .item.active.right {
-webkit-transform: translate3d( 0, 0, 0);
transform: translate3d( 0, 0, 0);
}
.carousel-inner > .item.prev,
.carousel-inner > .item.active.left {
-webkit-transform: translate3d( 0, 0, 0);
transform: translate3d( 0, 0, 0);
}
.carousel-inner > .item.next.left,
.carousel-inner > .item.prev.right,
.carousel-inner > .item.active {
-webkit-transform: translate3d(0, 0, 0);
transform: translate3d(0, 0, 0);
}
}
答案 1 :(得分:0)
扩展Sprazer所写的内容,这里是您可以使用的mixin版本,并将其添加到SCSS表的顶层:
@mixin carousel-fade() {
.carousel {
.carousel-inner {
>.item {
opacity: 0;
-webkit-transition-property: opacity;
transition-property: opacity;
@media all and (transform-3d), (-webkit-transform-3d) {
&.next,
&.active.right,
&.prev,
&.active.left,
&.next.left,
&.prev.right,
&.active {
-webkit-transform: translate3d( 0, 0, 0);
transform: translate3d( 0, 0, 0);
}
}
}
.active {
opacity: 1;
}
.active.left,
.active.right {
left: 0;
opacity: 0;
z-index: 1;
}
.next.left,
.prev.right {
opacity: 1;
}
}
.carousel-control {
z-index: 2;
}
}
}