我正在尝试使用 AngularJS 构建幻灯片,例如http://caroufredsel.dev7studios.com/带有箭头的幻灯片(下一个和上一个)。
这是HTML代码:
<div class="carousel">
<div class="left"><input type="button" value="Back" ng-click="slideBack()" ng-disabled="currentSlide == 0" /></div>
<div class="content">
<div class = "slide" ng-repeat="img in imgs | startFrom:currentSlide | limitTo:slidesSize" ng-animate="{enter: 'animate-enter', leave: 'animate-leave', move: 'animate-move'}">
<img ng-src="{{img.url}}" />
</div>
</div>
<div class="right"><input type="button" value="Next" ng-click="slideNext()" ng-disabled="currentSlide+slidesSize >= imgs.length" /></div>
</div>
CSS:
.animate-enter, .animate-move, .animate-leave
{
-webkit-transition: 1000ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-moz-transition: 300ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-ms-transition: 300ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-o-transition: 300ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
transition: 300ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
}
.animate-enter {
left: 400px;
position:relative;
opacity: 0;
}
.animate-enter.animate-enter-active {
left: 0px;
opacity: 1;
}
.animate-move {
position:relative;
}
.animate-move.animate-move-active{
left: -200px;
}
.animate-leave {
left: 0;
}
.animate-leave.animate-leave-active{
left: -100%;
position:absolute;
}
这是过滤器:
angular.module('carouselFilters', []).filter('startFrom', function() {
return function(input, start) {
start = +start;
return input.slice(start);
}
});
控制器:
function carouselCtrl($scope, $http) {
$scope.currentSlide = 0;
$scope.slidesSize = 3;
$http.get('carousel_images.json').success(function(data) {
$scope.imgs = data;
});
$scope.slideNext = function(){
$scope.currentSlide++;
}
$scope.slideBack = function(){
$scope.currentSlide--;
}
}
animate-enter 和 animate-leave 正常工作,但 animate-move 不起作用,知道吗?
谢谢。