AngularJS Directives - Dynamic
HTML
<script src="http://code.angularjs.org/angular-1.0.0rc5.min.js"></script>
<body>
<div ng-app="animateApp" ng-controller="AnimateCtrl">
<div class="boundingBox">
<div ng-repeat="shape in shapes"
class="{{shape.z}}"
ng-style="{ 'backgroundColor':shape.color, 'left':shape.x+'px', 'top':shape.y+'px' }"
/>
</div>
</div>
<script type="text/javascript">
</script>
</body>
CSS
.boundingBox {
width: 600px;
height: 600px;
background-color: #333333;
margin:20px;
}
.circle {
display:block;
position:absolute;
height: 20px;
width: 20px;
background-color: #999;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
border-radius: 15px;
}
.rectangle {
display:block;
position:absolute;
height: 20px;
width: 50px;
background-color: #999;
}
.square {
display:block;
position:absolute;
height: 30px;
width: 30px;
background-color: #999;
}
.box {
display:block;
position:absolute;
height: 20px;
width: 20px;
}
#controls {
position: absolute;
top: 620px;
}
JavaScript
var module = angular.module('animateApp', []);
function AnimateCtrl($scope, $defer) {
$scope.shapes = [];
$scope.shapes = [
{x : 250,y : 150,z : 'circle',color : 'green'},
{x : 150,y : 150,z : 'rectangle',color : 'red'},
{x : 350,y : 150,z : 'square',color : 'blue'}
];