JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.angularjs.org/1.2.15/angular.js"></script>
<script src="http://code.angularjs.org/1.2.15/angular-animate.js"></script>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<div ng-controller="MyCtrl">
<ul id="items">
<li ng-repeat="item in items" class="repeated-item">
<div class="close" ng-click="removeItem($index)">×</div>
{{item.label}}
</li>
</ul>
<button type="button" ng-click="addItem()">Add</button>
</div>
CSS
#items { list-style: none; }
.repeated-item {
position: relative;
margin: 3px 3px 3px 0;
padding: 1px;
width: 100px;
height: 90px;
font-size: 4em;
text-align: center;
border: solid 1px #333;
background-color: #eaa10e;
}
.close {
position: absolute;
top: 0;
right: 0;
width: 16px;
height: 16px;
line-height: 16px;
font-size: 16px;
color: white;
background-color: rgb(218, 77, 11);
border: 1px solid rgb(128, 0, 0);
}
.close:hover {
cursor: pointer;
background-color: rgb(255, 81, 0);
}
/*
* Animations
* ---------- */
.repeated-item.ng-enter {
-webkit-transition:0.5s linear all;
-moz-transition:0.5s linear all;
-o-transition:0.5s linear all;
transition:0.5s linear all;
max-height: 0;
opacity: 0;
left: -50px;
}
.repeated-item.ng-enter.ng-enter-active {
max-height: 90px;
opacity: 1;
left: 0;
}
.repeated-item.ng-leave {
-webkit-animation:0.5s my_animation;
-moz-animation:0.5s my_animation;
-o-animation:0.5s my_animation;
animation:0.5s my_animation;
}
@keyframes my_animation {
from {
max-height: 90px;
opacity: 1;
left: 0;
}
to {
max-height: 0;
opacity: 0;
left: -50px;
}
}
/*
Unfortunately each browser vendor requires
its own definition of keyframe animation code...
*/
@-webkit-keyframes my_animation {
from {
max-height: 90px;
opacity: 1;
left: 0;
}
to {
max-height: 0;
opacity: 0;
left: -50px;
}
}
@-moz-keyframes my_animation {
from {
max-height: 90px;
opacity: 1;
left: 0;
}
to {
max-height: 0;
opacity: 0;
left: -50px;
}
}
@-o-keyframes my_animation {
from {
max-height: 90px;
opacity: 1;
left: 0;
}
to {
max-height: 0;
opacity: 0;
left: -50px;
}
}
JavaScript
var myApp = angular.module('myApp', ['ngAnimate']);
myApp.controller('MyCtrl', function ($scope) {
$scope.items = []
$scope.counter = 1;
for (; $scope.counter <= 5; $scope.counter++) {
$scope.items.push({ label: $scope.counter });
}
$scope.addItem = function () {
$scope.items.push({ label: $scope.counter++ });
};
$scope.removeItem = function (index) {
$scope.items.splice(index, 1);
};
});
// Alternatively, you can use JavaScript-based animations.
// Simply get rid of the CSS-based animations, and uncomment
// below code.
/*
myApp.animation('.repeated-item', function () {
return {
enter: function (element, done) {
element.css({
left: '-50px',
height: 0,
opacity: 0
});
$(element).animate({
left: 0,
height: '90px',
opacity: 1
}, done);
return function (isCancelled) {
$(element).css('max-height', '');
};
},
leave: function (element, done) {
element.css({
height: $(element).css('height')
});
$(element).animate({
left: '50px',
height: 0,
//opacity: 0
}, done);
}
};
});
*/