example-reorder.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>ngDraggable</title>
  5. <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootswatch/2.3.1/spruce/bootstrap.min.css">
  6. <style>
  7. * {
  8. -moz-box-sizing: border-box;
  9. -webkit-box-sizing: border-box;
  10. box-sizing: border-box;
  11. }
  12. [ng-drag] {
  13. -moz-user-select: -moz-none;
  14. -khtml-user-select: none;
  15. -webkit-user-select: none;
  16. -ms-user-select: none;
  17. user-select: none;
  18. }
  19. [ng-drag] {
  20. width: 100px;
  21. height: 100px;
  22. background: rgba(255, 0, 0, 0.5);
  23. color: white;
  24. text-align: center;
  25. padding-top: 40px;
  26. display: block;
  27. cursor: move;
  28. }
  29. [ng-drag].one {
  30. background: rgba(255, 0, 0, 0.5);
  31. }
  32. [ng-drag].two {
  33. background: rgba(0, 255, 0, 0.5);
  34. }
  35. [ng-drag].three {
  36. background: rgba(0, 0, 255, 0.5);
  37. }
  38. [ng-drag].drag-over {
  39. border: solid 1px red;
  40. }
  41. [ng-drag].dragging {
  42. opacity: 0.5;
  43. }
  44. [ng-drop] {
  45. background: rgba(0, 0, 0, 0.25);
  46. text-align: center;
  47. display: block;
  48. position: relative;
  49. padding: 20px;
  50. width: 140px;
  51. height: 140px;
  52. float: left;
  53. }
  54. [ng-drop].drag-enter {
  55. border: solid 5px red;
  56. }
  57. [ng-drop] span.title {
  58. display: block;
  59. position: absolute;
  60. top: 50%;
  61. left: 50%;
  62. width: 200px;
  63. height: 20px;
  64. margin-left: -100px;
  65. margin-top: -10px;
  66. }
  67. [ng-drop] div {
  68. position: relative;
  69. z-index: 2;
  70. }
  71. .draglist {
  72. display: inline-block;
  73. margin: 0 auto;
  74. }
  75. </style>
  76. </head>
  77. <body ng-app="ExampleApp">
  78. <div class="row text-center">
  79. <h1>ngDraggable Ordering Example</h1>
  80. </div>
  81. <hr/>
  82. <div class="row text-center" ng-controller="MainCtrl">
  83. <ul class="draglist">
  84. <li ng-repeat="obj in draggableObjects" ng-drop="true" ng-drop-success="onDropComplete($index, $data,$event)">
  85. <div ng-drag="true" ng-drag-data="obj" ng-class="obj.name">
  86. {{obj.name}}
  87. </div>
  88. </li>
  89. </ul>
  90. </div>
  91. <hr/>
  92. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.min.js"></script>
  93. <script src="ngDraggable.js"></script>
  94. <script>
  95. angular.module('ExampleApp', ['ngDraggable']).
  96. controller('MainCtrl', function ($scope) {
  97. $scope.draggableObjects = [
  98. {name: 'one'},
  99. {name: 'two'},
  100. {name: 'three'}
  101. ];
  102. $scope.onDropComplete = function (index, obj, evt) {
  103. var otherObj = $scope.draggableObjects[index];
  104. var otherIndex = $scope.draggableObjects.indexOf(obj);
  105. $scope.draggableObjects[index] = obj;
  106. $scope.draggableObjects[otherIndex] = otherObj;
  107. }
  108. });
  109. </script>
  110. </body>
  111. </html>