ngDraggable.js是一款比较简单实用的angularJS拖拽插件,借助于封装好的一些自定义指令,能够快速的进行一些拖拽应用开发。首先先介绍一些基本的概念;
"external nofollow" href="https://github.com/fatlinesofcode/ngDraggable">https://github.com/fatlinesofcode/ngDraggable
在拖拽进行元素排序时,只需动态更改下循环数组元素顺序;具体事件绑定drop绑定在父元素,drag绑定在子元素即可,具体实现代码如下:
效果图如下:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <style> .drag-container { display: flex; justify-content: flex-start; align-items: center; } .drag-container .drag-box { display: flex; align-items: center; justify-content: center; width: 200px; height: 200px; margin: 20px; color: #fff; font-size: 20px; font-weight: bold; } .drag-container .drag-box .drag-item { display: flex; align-items: center; justify-content: center; width: 150px; height: 150px; } </style> <title>ng-dragger</title> </head> <body ng-app="app" ng-controller="draggerController"> <div class="drag-container"> <div ng-repeat="item in dragArr" class="drag-box" ng-drop="true" ng-drop-success="onDropComplete($index, $data, $event)"> <div class="drag-item" ng-drag="true" ng-drag-data="{{item}}" ng-style="{background: item.color}">{{item.text}}</div> </div> </div> <script src="/UploadFiles/2021-04-02/angular.js">总结
以上所述是小编给大家介绍的基于AngularJS拖拽插件ngDraggable.js实现拖拽排序功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!