I had to add some jQuery to the end of the code to determine when the css transition ends. Is there an angular way to do this?
jsfiddle works here
The way it works is to have an object containing the top and left coordinates, which are entered as a ng-style inline style.
Some of these objects are stored in an array. Whenever a css3 end transition event is detected, the next object is introduced.
Here is the HTML with angular directives.
<div id="mycontainer" ng-controller="mycontroller">
<div ng-repeat="item in mylist" id="item{{item.key}}" class="item" ng-style="myproperties({{item.key}})">{{item.value}}</div>
</div>
<div id="readout"></div>
Here is Javascript / Angular, you will see jQuery really added near the end.
var myapp = angular.module('myapp', []);
myapp.controller(
'mycontroller',
[
'$scope',
'$log',
function($scope, $log) {
$scope.mylist = [];
for (var i = 0; i < 6; i++) {
$scope.mylist[i] = {'key':i, 'value':i, 'inlinestyle':{'top':'60px','left': (i*60)+'px'}};
}
$scope.myproperties = function(arg) {
return $scope.mylist[arg].inlinestyle;
};
var anime = [
{'top':'120px','left':'50px', 'background':'#ccc'},
{'top':'150px','left':'120px', 'background':'#3cc'},
{'top':'60px','left':'120px', 'background':'#c3c'},
{'top':'120px','left':'130px', 'background':'#cc3'},
{'top':'150px','left':'160px', 'background':'#fff'}
];
var playhead = 0;
var saveTimeStamp = 0;
setTimeout(function(){
$scope.mylist[2].inlinestyle = anime[0];
$scope.$apply();
playhead++;
}, 1000);
$('html').on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(e){
if (( e.timeStamp != saveTimeStamp ) && (anime[playhead]) ) {
$('#readout').append('ended '+playhead+' '+JSON.stringify(anime[playhead])+'<br>');
saveTimeStamp = e.timeStamp;
$scope.mylist[2].inlinestyle = anime[playhead];
$scope.$apply();
playhead++;
}
});
}
]
);