function ctrl($scope){
// those variable are passed as param to the directive
$scope.selectedKey = 2
$scope.elements =
[
{
name: "Status 1",
key: 1,
description: "description status 1"
},
{
name: "Status 2",
key: 2,
description: "description status 2"
},
{
name: "Status 3",
key: 3,
description: "description status 3"
},
{
name: "Status 4",
key: 4,
description: "description status 4"
}
]
$scope.colors =
{
current: "lightblue",
success: "lightgreen",
disable: "lightgrey"
}
$scope.widthCalc = ($scope.elements.length - 1) * 26
$scope.getColor = function($index) {
if ($scope.elements[$index].key === $scope.selectedKey)
return $scope.colors['current']
if ($scope.elements[$index].key < $scope.selectedKey)
return $scope.colors['success']
if ($scope.elements[$index].key > $scope.selectedKey)
return $scope.colors['disable']
}
}
.block-container {
\t width: auto;
\t padding-top: 4px;
\t padding-right: 8px;
\t padding-left: 8px;
margin-bottom: -10px;
}
.block-head {
background-color: #4D81BF;
height: 20px;
line-height: 20px;
display: inline-block;
position: relative;
\t width:22px;
margin-right:4px;
\t margin-bottom: -5px;
}
.block-text {
color: black;
font-size: 14px;
\t margin-left: 50%;
}
.block-head:before {
color: #FAFAFA;
border-left: 10px solid;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
display: inline-block;
content: '';
\t z-index:1;
position: absolute;
top:0;
}
.block-head:after {
color: inherit;
\t z-index:2;
border-left: 10px solid;
border-top: 10px solid transparent;
border-bottom: 10px solid transparent;
display: inline-block;
content: '';
position: absolute;
right: -10px;
top:0;
}
.block-head-first {
margin-left:0px !important;
}
.block-head-last {
margin-right:0px;
}
.block-head-first:before {
color: #FAFAFA;
border-left: 0;
border-top: 0;
border-bottom: 0;
display: inline-block;
content: '';
\t z-index:1;
position: absolute;
top:0;
}
.block-head-last:after {
color: #4D81BF;
border-left: 0;
border-top: 0;
border-bottom: 0;
display: inline-block;
content: '';
\t z-index:1;
position: absolute;
top:0;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<!DOCTYPE html>
<html ng-app>
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.5/angular.min.js"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<meta charset=utf-8 />
<title>Angular JS Demo</title>
</head>
<body ng-controller="ctrl">
<div class="block-container">
<div ng-repeat="element in elements"
class="block-head"
ng-class="{'block-head-first': $first, 'block-head-last': $last}"
ng-style="{'width' : selectedKey === element.key ? 'calc(100% - ' + widthCalc + 'px)' : '',
'background-color': getColor($index),
'color': getColor($index)}">
<span class="block-text" ng-if="selectedKey === element.key">{{element.name}}</span>
</div>
</div>
</body>
</html>
まさに私が探していたものでした、ありがとう! –
@ GuillaumeRoche-Bayard喜んでそれは助けた:) – sol