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 ...
随机推荐
- iOS 之 线性布局
本来想自己写一个线性布局的类,看来不用了 ,网上已经有了,我先试试好不好用. https://github.com/youngsoft/MyLinearLayout 线性布局MyLinearLayou ...
- zip-auto.sh
#!/bin/sh #auto zip package #Define Path #####test######### mkdir -p /root/shell/test1 /root/shell/t ...
- Python装饰器学习(九步入门)
这是在Python学习小组上介绍的内容,现学现卖.多练习是好的学习方式. 第一步:最简单的函数,准备附加额外功能 ? 1 2 3 4 5 6 7 8 # -*- coding:gbk -*- '''示 ...
- ArcGIS Server的切图原理深入(转载)
http://forum.osgearth.org/template/NamlServlet.jtp?macro=search_page&node=2174485&query=arcg ...
- 用编程的方式定义UI界面
package com.example.administrator.test_hello_world; import android.app.Activity; import android.os.B ...
- xdebug.var_display_max_data
Xdebug Display Full Details on var_dump() Xdebug is an excellent addition to a PHP developers arsena ...
- Delphi在Vasta/win 7下通过UAC控制
在Windows编程时,为了兼容Win7与XP,许多需要底层权限的程序需要通过UAC验证,这是微软出的一个很恶心的东西……还不如Ubuntu那种Root机制呢……但是有困难我们就要克服-现在有一种方式 ...
- Ajax Not Found,asp.net mvc 中
x前台代码: <script type="text/javascript"> $(document).ready(function () { $("#btnS ...
- iOS 之 alcatraz (插件管理器)
1. 安装 1.1. 打开命令行 curl -fsSL https://raw.githubusercontent.com/supermarin/Alcatraz/deploy/Scripts/ins ...
- easyUI droppable组件使用
easyUI droppable组件使用: <!DOCTYPE html> <html lang="en"> <head> <meta c ...