ng-repeat
directive: // $scope.slides = [ { 'image': 'images/image1.png' }, { 'image': 'images/image2.png' } ];
<div ng-repeat="(i, slide) in slides"> <img ng-src="{{ slide.image }}" /> </div>
setInterval
function, therefore, to implement the perpetual timer, we will cyclically call $timeout
. To stop this timer, you need to use the $timeout.cancel
function. // $scope.next = function() { var total = $scope.slides.length; if (total > 0) { $scope.$slideIndex = ($scope.$slideIndex == total - 1) ? 0 : $scope.$slideIndex + 1; } }; // play , $scope.play = function() { timeOut = $timeout(function() { $scope.next(); $scope.play(); }, 2000); };
<div ng-repeat="(i, slide) in slides" ng-show="i == $slideIndex"> <img ng-src="{{ slide.image }}" /> </div>
.animation-fade.ng-hide-add, .animation-fade.ng-hide-remove { /* */ -webkit-transition: 1s linear all; -moz-transition: 1s linear all; -o-transition: 1s linear all; transition: 1s linear all; display: block !important; } .animation-fade.ng-hide-add, .animation-fade.ng-hide-remove.ng-hide-remove-active { /* */ opacity: 1; } .animation-fade.ng-hide-add.ng-hide-add-active, .animation-fade.ng-hide-remove { /* */ opacity: 0; position: absolute; }
animation-fade
class will have a animation-fade
effect on transitions.Source: https://habr.com/ru/post/197014/
All Articles