爲了解決我的問題,我用NG-風格=「的getStyle($指數,項目)「,我稱之爲功能。 任何時候我將新對象推入數組,ng重複調用getStyle。我的對象有一些適合我的CSS風格。
<div style="margin-left: 20px;" ng-repeat="item in template.list2">
<img ng-click="setBorder($index,true)" ng-focus="setBorder($index,true)" ng-blur="setBorder($index,false)"
ng-style="<%getStyle($index,item)%>" id="<%$index%>" ng-keydown="changed($event,item,$index,this)" tabindex="<%$index%>" ng-show="item.link"
src="<% item.link %>"
data-drag="<%item.drag%>"
data-jqyoui-options="{revert: 'invalid',snap:true,snapTolerance:15,zIndex:999,snapMode:'inner'}"
ng-model="template.list2"
jqyoui-draggable="{index: <%$index%>,placeholder:true,animate:true}"/>
</div>
$scope.changed = function (keyevent, item, id) {
keyevent.preventDefault();
switch (keyevent.keyCode) {
case 68:
if (keyevent.ctrlKey) {
left = parseInt($('#' + id).css("left").slice(0, -2));
top = parseInt($('#' + id).css("top").slice(0, -2));
item.left = left;
item.top = top;
item.duplicate = true;
item = angular.copy(item);
$scope.template.list2.push(item);
Notification.success("Imagem duplicada com sucesso!");
}
break;
}
$scope.getStyle = function (index, item) {
if(item.duplicate)
{
var top = item.top + 20;
var left = item.left +20;
var css = {
"position":'absolute',
"left":+ left + 'px',
"top": + top + 'px',
"height": item.height + 'px',
"width": item.width + 'px',
'z-index': 999
};
}else{
var css = {
"float": 'left',
"left": (item.width * index + 5) + "px",
"position":'absolute',
"height": item.height,
"width": item.width,
"display": 'inline-block'
};
}
return css;
}
}