这是原文 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) 笔记的更多相关文章

  1. angular drag and drop (marceljuenemann) 笔记

    这是原文 http://marceljuenemann.github.io/angular-drag-and-drop-lists/demo/#/simple 看起来很多功能,所以我只记入我需要的部分 ...

  2. angularjs drag and drop

    angular-dragula Drag and drop so simple it hurts 480 live demo angular-drag-and-drop-lists Angular d ...

  3. Angular7 Drag and Drop

    完整代码在最后,下面讲解以此代码为例 1.环境配置 1.1 安装@angular/material.@angular/cdk cnpm install --save @angular/material ...

  4. 拖放API中的drag和drop实战

    原文地址:→传送门 写在前面 在HTML5之前,实现拖放功能需要借助mousedown/mousemove/mouseover/mouseout/mouseup等鼠标事件来完成,HTML5中拖放API ...

  5. Angular Material (Components Cdk) 学习笔记 Table

    refer : https://material.angular.io/cdk/table/overview https://material.angular.io/components/table/ ...

  6. WPF开发快速入门【7】WPF的拖放功能(Drag and Drop)

    概述 本文描述WPF的拖放功能(Drag and Drop). 拖放功能涉及到两个功能,一个就是拖,一个是放.拖放可以发生在两个控件之间,也可以在一个控件自己内部拖放.假设界面上有两个控件,一个Tre ...

  7. HTML5 之拖放(drag与drop)

    拖放(Drag 和 drop)是 HTML5 标准的组成部分. 拖放是一种常见的特性,即抓取对象以后拖到另一个位置. 在 HTML5 中,拖放是标准的一部分,任何元素都能够拖放. HTML5 拖放实例 ...

  8. 通过HTML5的Drag and Drop生成拓扑图片Base64信息

    HTML5 原生的 Drag and Drop是很不错的功能,网上使用例子较多如 http://html5demos.com/drag ,但这些例子大部分没实际用途,本文将搞个有点使用价值的例子,通过 ...

  9. 基于HTML5的Drag and Drop生成图片Base64信息

    HTML5的Drag and Drop是很不错的功能,网上使用例子较多如 http://html5demos.com/drag ,但这些例子大部分没实际用途,本文将搞个有点使用价值的例子,通过Drag ...

随机推荐

  1. Oracle用户管理和角色管理

    原博:http://liwx.iteye.com/blog/1182251 一.创建用户的Profile文件 SQL> create profile student limit // stude ...

  2. pku2104

    传送门:http://poj.org/problem?id=2104 题目大意:给定一个长度为N的数组{A[i]},你的任务是解决Q个询问.每次询问在A[l], A[l+1], ...... , A[ ...

  3. UVa 11129 - An antiarithmetic permutation

    题目大意:给一个正整数n,构造一个0...n-1的排列,使得这个排列的任何一个长度大于2的子序列都不为等差数列. 把序列按照奇偶位置分成两个序列,这样在两个序列间就不会形成等差数列了,然后再对这两个序 ...

  4. 优酷、YouTube、Twitter及JustinTV几个视频网站的架构

      优酷视频网站架构 一.网站基本数据概览据2010年统计,优酷网日均独立访问人数(uv)达到了8900万,日均访问量(pv)更是达到了17亿,优酷凭借这一数据成为google榜单中国内视频网站排名最 ...

  5. Grunt构建工具插件篇——之less工具3和watch配合自动化编译

    grunt less转换成css速度慢 而且页面会全部刷新? 最近遇到了个问题,grunt里用less,当修改完.less里面的样式,对应 的.css文件会好几秒才修改,然后浏览器上显示也会耗时好几秒 ...

  6. 利用cocoapods创建基于git的私有库

    上一篇文章记录了我利用cocoapods创建基于SVN的私有库的全部过程,今天我再记录一下基于git创建的过程. 整体先说明一下创建一个私有的podspec包括如下那么几个步骤: 创建并设置一个私有的 ...

  7. 在centos 6.5 x64中安装 spark-1.5.1

    以下内容参考:http://blog.csdn.net/lovehuangjiaju/article/details/48494737 1.解压安装文件,设置环境变量 这里我们使用的安装文件是已经编译 ...

  8. Java语言中IO流的操作规律学习笔记

    1,明确源和目的. 数据源:就是需要读取,可以使用两个体系:InputStream.Reader: 数据汇:就是需要写入,可以使用两个体系:OutputStream.Writer: 总结: 读:就是把 ...

  9. 升级wamp5集成安装包 php5.2到php5.3

    平时xp下面都使用wamp5集成开发 但php的空间命名需要php5.3 才支持,而且公司系统大部分都使用5.3,很多函数与5.2是不同的 难的在xp下面手动安装,集成包使用很方便,配置,快捷键都很不 ...

  10. delphi公用函数

    {*******************************************************} { } { Delphi公用函数单元 } { } { 版权所有 (C) 2008 } ...