I've been playing around with the animation aspect in AngularJS, and I just can't seem to get the kind of functionality I need:
.box.ng-hide-add {-webkit-animation: fadeOutLeftBig 0.4s;}
.box.ng-hide-remove {-webkit-animation: fadeInRightBig 0.4s;}
.box.ng-show-add{-webkit-animation: fadeInRightBig 0.4s;}
Ideally, when the user hits the 'Next' button, the current box should exit to the left, while the box next in line eases in from the right, creating that slideshow/carousel effect.
But right now it's all from the same side.
Is this even possible? I feel like I'm getting close, but I could just be thinking about it the wrong way. What am I overlooking or forgetting?
Code snippet:
(function(){
var app = angular.module("theapp", ['ngAnimate']);
var controller = function($scope){
$scope.currentPage = 1;
};
app.controller("controller", controller);
}());
.box.ng-hide-add {
-webkit-animation: fadeOutLeftBig 0.4s;
}
.box.ng-hide-remove {
-webkit-animation: fadeInRightBig 0.4s;
}
.box.ng-show-add {
-webkit-animation: fadeInRightBig 0.4s;
}
.box {
height:100px;
width:100px;
}
.red {background-color:red;}
.blue {background-color:blue;}
.purple {background-color:purple;}
<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.0/animate.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.1/angular-animate.min.js"></script>
<body ng-app="theapp">
<div ng-controller="controller">
<div style="height:100px; margin-left:300px;">
<div ng-show="currentPage==1" class="box red">
content
</div>
<div ng-show="currentPage==2" class="box blue">
content
</div>
<div ng-show="currentPage==3" class="box purple">
content
</div>
</div>
<button ng-click="currentPage=currentPage-1">Previous</button>
<button ng-click="currentPage=currentPage+1">Next</button>
</div>
</body>
Any help is appreciated!
displayis immediately set tononefor the box that should fade out. So even if the animation is technically taking place, you wouldn't see it because the box is removed from the page. So that would be my next step: find out how to delay thedisplay:noneuntil after the animation is finished. (Keep in mind, I have never used AngularJS, but this is just what I observe)