这是原文 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. Swift 添加到TableView实现动画效果

    let indexPath = NSIndexPath(forRow:0 ,inSection:0) self.tableView.insertRowsAtIndexPaths([indexPath] ...

  2. arcgis 瓦片图加载规则(转载)

    arcgis 瓦片图加载规则 最近需要做地图离线的功能,要能下载指定区域的瓦片图,我们都知道如何加载谷歌和天地图的加载规则,但是网上貌似没有找到如何加载arcgis自己发布的瓦片图规则,好不容易找到一 ...

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

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

  4. Selenium2(java)selenium常用API 四

    WebElement相关方法 1.点击操作 WebElement button = driver.findElement(By.id("login")); button.click ...

  5. windows apache 开启 GZIP

    从服务端优化来说,通过对服务端做压缩配置可以大大减小文本文件的体积,从而使加载文本的速度成倍的加快.目前比较通用的压缩方法是启用gzip压缩.它 会把浏览器请求的页面,以及页面中引用的静态资源以压缩包 ...

  6. 在代码中控制UI界面

    虽然Android推荐使用XML布局文件来控制UI界面,但如果开发者愿意,Android允许开发者完全抛弃XML布局文件,完全在Java代码中控制UI界面. 实例:用编程的方式开发UI界面 packa ...

  7. Maven与Antx(整理)

    http://blog.csdn.net/ghost_t/article/details/5709640 一.Maven与Antx概况: Antx简介   在讲为什么使用maven之前我想说一下,an ...

  8. VS生成时复制文件到指定目录

    1.右键项目属性,选择生成事件,再点击"编辑后生成事件",可以直接在编辑框内填写命令行,如图: 2.也可以在弹出的编辑框内,写命令,$(ProjectDir)这种是系统的宏路径,具 ...

  9. CocosBuilder 多分辨率基础

    最近两个项目大量使用了CocosBuilder, 对于开发效率提高是巨大的. 一直计划写一篇博客谈谈CocosBuilder的多分辨率问题, 懒病加上一些疙疙瘩瘩的小事情, 拖延了一个多月, 才终于下 ...

  10. VoiceEngine获取硬件信息

    #include "webrtc\voice_engine\include\voe_base.h" #include "webrtc\voice_engine\inclu ...