角落物品停留在下降位置

时间:2016-01-29 18:03:20

标签: angularjs angularjs-directive drag-and-drop jquery-ui-droppable angular-dragdrop

我使用angular-dragdrop将图片从div移动到另一个div。由于每个div都有自己的$scope列表,当我将一个元素从一个列表中删除到另一个列表时,将更新接收该项目的列表。

然而,当我将物品放入可放置区域时,它会进入左上角。它不会留在我丢弃的地方

enter image description here

这是我的HTML

可拖动

<div class="sand-image" ng-repeat="item in filtered = (products  | filter: {cat : config.category.id}:true) | 
itemsPerPage: pageSize" 
current-page="currentPage"
data-drag="true" 
data-jqyoui-options="{revert: 'invalid', helper: 'clone'}" 
ng-model="products" 
jqyoui-draggable="{index:$index,applyFilter:'{{getIndex(item)}}',
placeholder: 'keep',deepCopy :true}"
></div>

可投放

<div class="wrap" id="sand-ground" 
data-drop="true" 
ng-model='box' 
jqyoui-droppable="{multiple:true, deepCopy:true ,onOver :'stop',containment :'position'}" >
<!-- item html -->
 <div class="draggable" ng-repeat="item in box track by $index" resizable  ><img src="{{item.url}}" ></div>

第二个列表中的项目(可丢弃)有一个指令(可调整大小),用于为项目设置一些信息。

如何让掉落的物品停留在掉落位置?

1 个答案:

答案 0 :(得分:4)

$scope.dropAction = function(event, ui) {
     console.log('left:', ui.position.left, 'top:', ui.position.top, ui);
     // update model
     var newItem = {
          left:, ui.position.left, 
          top:, ui.position.top
     };
     $scope.someList.push(newItem);
};

由于您可以在drop函数中捕获位置,因此我决定只更新管理每个可拖动项目位置的模型。在你的drop函数中:

jqyoui-droppable="{onDrop: 'dropaction($event)'}" 

然后在您的标记中,您可以重复这些项目并使用存储的属性以内联ng样式定位它们。

ng-repeat="item in someList" ng-style="{'left': item.left, 'top': item.top}"

这些是我所做的基础知识,您很可能需要扩展它以适合您的使用。在我的情况下,这捕获像素,我转换为百分比,以获得响应的位置。我还发布了一个$ uibModal,它在我放置之前会获取有关我的项目的更多信息。

相关问题