Here I have a $scope.content
with a paragraph of text. When a user clicks the next button, I replace the $scope.content
text.
This text transition isn't very smooth, so I would like to add a simple transition fade in the following order:
- User click the next button
- The current
$scope.content
div will fade out - After the fade out animation has completed, replace the
$scope.content
- Then instantly show the new text (no animation)
angular
.module('app', [])
.controller('Controller', function ($scope) {
var data = [
'Here is slide #1',
'Another slide, it is #2',
'Can I get another? Yep! #3',
'Last but not least, slide #4'
];
$scope.slide = 0;
$scope.content = data[$scope.slide];
$scope.next = function () {
$scope.slide++;
$scope.content = data[$scope.slide];
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="Controller">
<div>{{content}}</div>
<button ng-click="next()">Next</button>
</div>