angular drag and drop (ngDraggable) 笔记
这是原文 https://github.com/fatlinesofcode/ngDraggable
这是另一个dnd,这比较灵活,可以监听事件。我只用简单的排序功能,其他没去了解太多。有机会遇到功能扩展,会在这里更新。
功能与需求:
-在angular filter orderBy 里 reorder 对象。
基本注入一下和写些controller
var app = angular.module('App', ['ngAnimate','ngDraggable']);
app.controller("App.ctrl", ['$scope', '$timeout', function ($scope, $timeout) {
$scope.FAQs = [
{
id:1,
question: 'q1',
answer: 'a1',
sort : 1
},
{
id: 2,
question: 'q2',
answer: 'a2',
sort: 2
},
{
id: 3,
question: 'q3',
answer: 'a3',
sort: 3
}
];
$scope.onDropComplete = function (dragResource, dropResource) {
var sortRecord = dragResource.sort;
dragResource.sort = dropResource.sort;
dropResource.sort = sortRecord;
}
}])
</script>
HTML
<div
ng-repeat="FAQ in FAQs | orderBy : 'sort' : true"
ng-drop="true"
ng-drop-success="onDropComplete($data,FAQ)" class="card-panel "> <div ng-drag="true" ng-drag-data="FAQ" class="row">
<div class="col s10">
<p>{{FAQ.question}}</p>
<p>{{FAQ.answer}}</p>
</div>
<div class="col s2 center">
<a class="btn-floating waves-effect waves-light"><i class="mdi-action-delete"></i></a>
<a href="#createFAQ" class="btn-floating waves-effect waves-light modal-trigger"><i class="mdi-editor-mode-edit"></i></a>
</div>
</div>
</div>
CSS
[ng-drag] {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
-moz-user-select: -moz-none;
-khtml-user-select: none;
-webkit-user-select: none;
-ms-user-select: none;
user-select: none;
}
[ng-drag] {
cursor: move;
}
[ng-drag].drag-over {
//开始drag位置,去到其他elem是没有反应的,这里是设计错误
}
[ng-drag].dragging {
//开始drag位置
background-color: #e8f5e9 ;
}
[ng-drop] {
}
[ng-drop].drag-enter {
//drag进入
background-color: #f1f8e9;
}
[ng-drop] div {
//这是为了在drag时,可以在所有elem的之上
position: relative;
z-index: 2;
}
原理:
在drag complete时,出发事件,把2个对象的sort对换。
angular drag and drop (ngDraggable) 笔记的更多相关文章
- angular drag and drop (marceljuenemann) 笔记
这是原文 http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple 看起来很多功能,所以我只记入我需要的部分 ...
- angularjs drag and drop
angular-dragula Drag and drop so simple it hurts 480 live demo angular-drag-and-drop-lists Angular d ...
- Angular7 Drag and Drop
完整代码在最后,下面讲解以此代码为例 1.环境配置 1.1 安装@angular/material.@angular/cdk cnpm install --save @angular/material ...
- 拖放API中的drag和drop实战
原文地址:→传送门 写在前面 在HTML5之前,实现拖放功能需要借助mousedown/mousemove/mouseover/mouseout/mouseup等鼠标事件来完成,HTML5中拖放API ...
- Angular Material (Components Cdk) 学习笔记 Table
refer : https://material.angular.io/cdk/table/overview https://material.angular.io/components/table/ ...
- WPF开发快速入门【7】WPF的拖放功能(Drag and Drop)
概述 本文描述WPF的拖放功能(Drag and Drop). 拖放功能涉及到两个功能,一个就是拖,一个是放.拖放可以发生在两个控件之间,也可以在一个控件自己内部拖放.假设界面上有两个控件,一个Tre ...
- HTML5 之拖放(drag与drop)
拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. HTML5 拖放实例 ...
- 通过HTML5的Drag and Drop生成拓扑图片Base64信息
HTML5 原生的 Drag and Drop是很不错的功能,网上使用例子较多如 http://html5demos.com/drag ,但这些例子大部分没实际用途,本文将搞个有点使用价值的例子,通过 ...
- 基于HTML5的Drag and Drop生成图片Base64信息
HTML5的Drag and Drop是很不错的功能,网上使用例子较多如 http://html5demos.com/drag ,但这些例子大部分没实际用途,本文将搞个有点使用价值的例子,通过Drag ...
随机推荐
- add jars和add external jars有什么区别
原文add jars和add external jars有什么区别? add jars和add external jars有什么区别? add external jars = 增加工程外部的 ...
- imageX及其安装windows
/capture 将卷映像捕获到新 WIM 文件中(备份成wim) imagex /capture g: e:\7setted.wim "Drive G" /apply ...
- centos 6.5下cmake工具的安装与配置
一.cmake是什么? CMake是一个跨平台的安装(编译)工具,可以用简单的语句来描述所有平台的安装(编译过程).他能够输出各种各样的makefile或者project文件,能测试编译器所支持的C+ ...
- 启动子&外显子&内含子
启动子 http://baike.baidu.com/link?url=HMqaMY4mXusH--4hMu1p6P_XUzEve9lZhFGtxScnbb8Z9HaLYJ981eWxAuZt2iAP ...
- AngularJS 讲解五, Factory ,Service , Provider
一. 首先说一下,为什么要引入Factory,Service和Provider这三个Service层. 1.因为我们不应该在controller层写入大量的业务逻辑和持久化数据,controller层 ...
- PHP 绘图技术
1.图片格式:目前网站开发常见的图片格式有gif,jpg/jpeg,png ..... 区别: gif 图片压缩率高,但是只能显示256色,可能造成颜色的丢失,可以显示动画 jpg/jpeg 图片压缩 ...
- js架构设计模式——从angularJS看MVVM
javascript厚积薄发走势异常迅猛,导致现在各种MV*框架百家争雄,MVVM从MVC演变而来,为javascript注入了全新的活力.我工作的业务不会涉及到 angularJS[ng] 这么重量 ...
- js架构设计模式——你对MVC、MVP、MVVM 三种组合模式分别有什么样的理解?
你对MVC.MVP.MVVM 三种组合模式分别有什么样的理解? MVC(Model-View-Controller)MVP(Model-View-Presenter)MVVM(Model-View-V ...
- because of many connection errors; unblock with 'mysqladmin flush-hosts
环境:linux,mysql5.5.37 错误:Host is blocked because of many connection errors; unblock with 'mysqladmin ...
- Spring classPath:用法
http://blog.csdn.net/xing_sky/article/details/8228305 参考文章地址: http://hi.baidu.com/huahua035/item/ac8 ...