我正在尝试在按键时创建图像的副本。问题是当我将副本推送到我的对象数组以更改 css 左上角位置时不起作用。我认为 ng-repeat 仍在加载 html。有没有办法让 Promise 或其他东西来复制图像,并在 ng-repeat 添加我的新对象后更改 css?
$scope.changed = function (keyevent, item, id) {
keyevent.preventDefault();
switch (keyevent.keyCode) {
case 68:
if (keyevent.ctrlKey) {
left = $('#' + id).css("left").slice(0, -2);
top = $('#' + id).css("top").slice(0, -2);
item.duplicate = true;
item = angular.copy(item);
itemId = $scope.items.push(item);
imagePosition(itemId - 1, left, top);
}
break;
}
}
function imagePosition(id, left, top) {
$("#" + id).css({left: left, top: top});
}
最佳答案
以 Angular 形式 $("#"+ id).css({left: left, top: top});
这不会工作,因为它是 jquery for Angular,你可以使用
document.getElementById("yourDivId"+id).style.top= top;
document.getElementById("yourDivId"+id).style.left= left;
关于javascript - angularjs 如何使用.push克隆具有相同位置的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42934490/