Chapter 3: Creating enter animations with ng-if

by billy roberts

HTML

<script src="https://code.angularjs.org/1.3.2/angular.min.js"></script>
<script src="https://code.angularjs.org/1.3.2/angular-animate.min.js"></script>
<div ng-app="myApp">
    <div ng-controller="Ctrl">
        <button ng-click="visible=!visible">Toggle</button>
        <span class="target" ng-if="visible">Bring me in!</span>
    </div>   
</div>

CSS

.target.ng-enter {
    animation: 1s target-enter;
    -webkit-animation: 1s target-enter;
}
@keyframes target-enter {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-webkit-keyframes target-enter {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}

JavaScript

// same thing as below with CSS# key frames
angular.module('myApp', ['ngAnimate'])
.controller('Ctrl', function($scope) {
    $scope.visible = true;
});