如何将项目拖放到外部容器
How to drag and drop items to external container?
基本上,我有以下标记:
<script>
$(function() {
$('.box').on('mousedown', function(e) {
console.log(e);
});
});
</script>
<body ng-controller="MainCtrl">
<ul ui-sortable="sortableOptions" ng-model="list">
<li draggable ng-repeat="item in list">Item: {{item}}</li>
</ul>
<div class="boxes">
Drop to external area: <br/><br/>
<div class="box" style="background: red;"></div>
<div class="box" style="background: yellow;"></div>
<div class="box" style="background: orange;"></div>
</div>
</body>
小提琴:http://plnkr.co/edit/xKw6sSbymA5M8R2v4OGF?p=preview
现在,我希望能够将列表中的项目拖放到该"外部"容器中。
当用户将项目"拖放"到任何彩色区域时,我想知道事件刚刚发生以及哪个元素受到影响
已经尝试侦听每个.box
元素上的mousedown/mouseup
事件,但它没有按预期工作。
您正在使用的库正在排序库。为此,您需要使用拖放库。
例如,您可以使用 https://github.com/codef0rmer/angular-dragdrop
有关所有可用的事件回调,请参阅文档。
直接复制示例代码片段(此处查看参考),
.HTML:
<ul class="thumbnails">
<li style='margin-left:10px;' ng-repeat="item in list1">
<div class="btn"
data-drop="true"
ng-model='list1'
jqyoui-droppable="{index: {{$index}}}">
<div class="btn btn-info"
ng-show="item.title"
data-drag="{{item.drag}}"
data-jqyoui-options="{revert: 'invalid'}"
ng-model="list1"
jqyoui-draggable="{index: {{$index}},placeholder:true,animate:true}">
{{item.title}}
</div>
</div>
</li>
</ul>
<div class="container form-inline" style="text-align: center;">
<div class="btn"
ng-repeat="item in list2 | orderBy : 'title'"
data-drop="true"
ng-model='list2'
jqyoui-droppable="{index: {{$index}}, applyFilter: 'filterIt'}">
<div class="btn btn-info"
data-drag="{{item.drag}}"
data-jqyoui-options="{revert: 'invalid'}"
ng-model="list2"
jqyoui-draggable="{index: {{$index}},animate:true, applyFilter: 'filterIt'}"
ng-hide="!item.title">
{{item.title}}
</div>
</div>
</div>
控制器:
App.controller('YourCtrl', function($scope, $filter) {
$scope.filterIt = function() {
return $filter('orderBy')($scope.list2, 'title');
};
$scope.list1 = [];
$scope.list2 = [
{ 'title': 'Item 3', 'drag': true },
{ 'title': 'Item 2', 'drag': true },
{ 'title': 'Item 1', 'drag': true },
{ 'title': 'Item 4', 'drag': true }
];
angular.forEach($scope.list2, function(val, key) {
$scope.list1.push({});
});
});
希望这能解决您的问题。
尝试将"鼠标按下"替换为"drop"。
相关文章:
- EaseJS拖放;放下(动画CC)电影剪辑的鼠标坐标
- 为什么HTML5拖放的目标是孩子?(可排序列表)
- HTML/CSS-用于拖放的全页面覆盖
- Rubaxa可与聚合物进行排序/拖放不起作用,具体取决于显示器:
- dblclick事件是在jquery拖放后触发的
- 无法进行拖放以使用本地存储
- 如何使用Java脚本创建提交按钮's的拖放功能
- Chrome原生拖放相对容器并不能正确渲染重影
- 如何在Javascript中创建排序、拖放多级列表
- html5拖放文件-在提交整个表单时上传
- 在jQuery UI中获取ul和li值,拖放即可排序
- html5拖放确定拖动项目的来源
- 我使用什么语言来创建像Webly这样的拖放功能
- HTML5拖放;Drop-使用jQuery处理事件
- 使用jquery拖放图像
- HTML5拖放访问属性
- HTML5拖放-如何删除IE上的默认重影图像
- jQuery拖动&拖放-只允许从浏览器外部拖动
- 在拖放过程中从外部远程图像读取URL数据
- 如何从外部HTML应用iframe的拖放操作