【发布时间】:2013-10-16 19:00:43
【问题描述】:
我正在使用来自 here 的代码使用 Angularjs 创建一个图像滑块
使用 AngularJS 1.15,我可以让图像滑入。但是当第二个图像进来时,第一个图像会消失而不是滑出。有人可以帮忙吗?
注意:这不适用于 Firefox 和 IE,但适用于 Chrome。
这是我的代码 HTML
<div ng-controller="slideShowController" class="imageslide" ng-switch='slideshow' ng-animate="'animate'">
<div class="slider-content" ng-switch-when="1">
<img src="asset/building.jpg" width="100%" height="400px"/>
</div>
<div class="slider-content" ng-switch-when="2">
<img src="asset/slide-2.jpg" width="100%" height="400px"/>
</div>
<div class="slider-content" ng-switch-when="3">
<img src="asset/slide-3.jpg" width="100%" height="400px"/>
</div>
<div class="slider-content" ng-switch-when="4">
<img src="asset/slide-4.jpg" width="100%" height="400px"/>
</div>
</div>
Javascript
function slideShowController($scope, $timeout) {
var slidesInSlideshow = 4;
var slidesTimeIntervalInMs = 3000;
$scope.slideshow = 1;
var slideTimer =
$timeout(function interval() {
$scope.slideshow = ($scope.slideshow % slidesInSlideshow) + 1;
slideTimer = $timeout(interval, slidesTimeIntervalInMs);
}, slidesTimeIntervalInMs);
}
CSS
.imageslide{
width:100%;
height:400px;
margin: 0 auto;
margin-bottom: 20px;
}
.imageslide .slider-content {
position: absolute;
width:100%;
height:400px;
}
.animate-enter,.animate-leave {
-webkit-transition:1000ms cubic-bezier(.165,.84,.44,1) all;
-moz-transition:1000ms cubic-bezier(.165,.84,.44,1) all;
-ms-transition:1000ms cubic-bezier(.165,.84,.44,1) all;
-o-transition:1000ms cubic-bezier(.165,.84,.44,1) all;
transition:1000ms cubic-bezier(.165,.84,.44,1) all;
}
.animate-enter {
left:100%;
}
.animate-leave.animate-leave-active {
left:-100%;
}
.animate-enter.animate-enter-active,.animate-leave {
left:0;
}
【问题讨论】:
-
你能发布一个 plunkr 或 jsfiddle 来演示这个问题吗?
-
fiddle 不支持 angularjs 1.1.5。尝试使用 plunker,但结果与我在系统中看到的不同。 plnkr.co/edit/sV1xckE7SCyMX9b3dVT0 给你。
-
好的。它适用于 chrome,但不适用于 Firefox 和 IE
-
我添加了一个答案。确保你在你的 html 上放置了一个 ng-app(你的 plunkr 没有它就无法工作),我认为一些浏览器在动画左侧存在问题。我把它换成了
margin-left,它在chrome和ff中工作。 IE 可能会也可能不会。