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 ...
随机推荐
- n皇后问题 [随机化算法,拉斯维加斯算法]
问题: 如何能够在 n×n 的国际象棋棋盘上放置八个皇后,使得任何一个皇后都无法直接吃掉其他的皇后?为了达到此目的,任两个皇后都不能处于同一条横行.纵行或斜线上. 分析: 这题常规的解法应该是回溯法, ...
- Sublime Text3 使用手册
1.标签页切换:ctrl+tab 2.Sublime Text3的配色方案(Preferences——配色方案)我选白色方案是:Eiffel;深色方案我选:Monokai 3.左边资源栏:先ctrl+ ...
- ios 清除列表选中状态
[tableView deselectRowAtIndexPath:indexPath animated:YES];
- linux 同步机制之complete【转】
转自: http://blog.csdn.net/wealoong/article/details/8490654 在Linux内核中,completion是一种简单的同步机制,标志"thi ...
- PHP中的date函数中时区问题
从php5.1.0开始,php.ini里加入了date.timezone这个选项,默认情况下是关闭的,也就是显示的时间(无论用什么php命令)都是格林威治标准时间,所以才会有这个情况发生 解决方法如下 ...
- Spring util-namespace下标签相关操作
java代码 package com.stono.sprtest; import java.util.List; import java.util.Map; import java.util.Set; ...
- node源码详解(七) —— 文件异步io、线程池【互斥锁、条件变量、管道、事件对象】
本作品采用知识共享署名 4.0 国际许可协议进行许可.转载保留声明头部与原文链接https://luzeshu.com/blog/nodesource7 本博客同步在https://cnodejs.o ...
- 在windows下运行spark
1.下载spark:spark-2.0.0-bin-hadoop2.7.tgz 2.解压至D:\bigdata\spark-2.0.0-bin-hadoop2.7 3.配置环境变量 HADOOP_HO ...
- Spring 集成 Dubbo
Duboo是什么 DUBBO是一个分布式服务框架,致力于提供高性能和透明化的RPC远程服务调用方案,是阿里巴巴SOA服务化治理方案的核心框架,每天为2,000+个服务提供3,000,000,000+次 ...
- JS消化理解
JS执行的时候是必须在网页里面执行,和样式表差不多,也是内嵌的样式表,嵌在网页里面或外部的! 一 嵌在网页里面怎么嵌? 如果你想在网页里面嵌脚本,你需要在网页里面打出一块区域,这块区域来写脚本,在写样 ...