I'm trying to animate a list of tiles off screen while at the same time animating a new list of tiles on screen.
I'm using Angular's ng-for to loop through an array of visible items, so there is technically only one list, but Angular's ngAnimate module keeps the evicted items alive until the animations are done.
My issue is that whenever both lists of tiles are on screen at the same time in the middle of the animation, one overflows and ends up below the other.
This is what is happening:
This is what I want it to do:
I've tried messing with CSS transforms, absolute positioning, but I can't seem to get it right.
Here's a fiddle with a working example of this: http://jsfiddle.net/soethzfm/7/
(function() {
var app = angular.module("animationApp", ["ngAnimate"]);
app.controller('FrameController', ['$scope',
function($scope) {
$scope.message = 'Hello world';
$scope.items = [];
$scope.visibleItems = [];
for (var i = 3; i < 9; i++) {
$scope.items.push({
name: 'Item ' + (i - 2),
color: "#" + (i) + "0" + (i % 5) + "0" + (i % 4) + '0'
});
}
$scope.firstThree = true;
$scope.selectNextItems = function() {
if ($scope.firstThree) {
$scope.firstThree = false;
$scope.visibleItems = [$scope.items[0], $scope.items[1], $scope.items[2]];
} else {
$scope.firstThree = true;
$scope.visibleItems = [$scope.items[3], $scope.items[4], $scope.items[5]];
}
}
$scope.selectNextItems();
}
]);
})()
.item-container {
width: 400px;
border: 1px solid red;
overflow: hidden;
}
.item {
color: white;
width: 100px;
height: 150px;
border: 5px solid #F3F5F6;
display: inline-block;
position: relative;
cursor: pointer;
}
.item:hover {
padding: 2px;
border: 3px solid blue;
}
/* Animations */
.item.ng-move,
.item.ng-enter,
.item.ng-leave {
-webkit-transition: 1400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-moz-transition: 1400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-ms-transition: 1400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
-o-transition: 1400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
transition: 1400ms cubic-bezier(0.250, 0.250, 0.750, 0.750) all;
}
.item.ng-enter,
.item.ng-move {
left: -100%;
}
.item.ng-enter.ng-enter-active,
.item.ng-move.ng-move-active {
left: 0;
}
.item.ng-leave {
right: 0;
}
.item.ng-leave.ng-leave-active {
right: -100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular-animate.min.js"></script>
<div ng-app="animationApp">
<div ng-controller="FrameController as vm">
<button ng-click="selectNextItems()">Next Page</button>
<div class="item-container">
<div class="item" ng-repeat="item in visibleItems" ng-style="{'background-color': item.color}">
{{item.name}}
</div>
</div>
</div>
</div>

