javascript - 如何将项目从一个桶移动到另一个 - DragulaJS-Angular

标签 javascript angularjs dragula angular-dragula

嘿,我正在使用 DragulaJS-Angular版本为了获得两个桶之间拖放的效果。 这个库有几个问题。 第一个,我可以移动只属于同一个桶的项目,如果我定义了不同的桶,那么我不能在它们之间移动项目。

对我的代码和我的目标进行重新分级的说明:

我有 3 个 div,第一个容器、第二个容器和第三个容器。

我的主要目标是:

1.仅将元素从容器一和容器二传递到容器三。

2.一号货柜和二号货柜之间不允许转运元素。

3.此外,我想为从容器一传输的每个项目添加类||第二个容器到第三个容器。

  1. 我还希望能够清洁袋子并重置系统。

5.我想制作一个将元素从一个袋子传递到另一个袋子的动画,目前的动画还不够。我还需要在两个容器之间查看拖动元素,而不仅仅是在其中一个容器中。 我的代码:

var app =  angular.module("app",[angularDragula(angular)]);
app.controller('MainCtrl', function($scope, dragulaService) {
  dragulaService.options($scope, 'first-bag', {
      copy: true
    });
});
.container {
    float: left;
    width: 48%;
    margin-right: 2%;
    padding: 10px;
    min-height: 300px;
    background-color: rgba(0, 0, 0, 0.2);
    transition: opacity 0.4s ease-in-out;
    cursor: move;
    cursor: grab;
    cursor: -moz-grab;
    cursor: -webkit-grab;
    box-sizing: border-box;
}
.container div {
    padding: 10px 15px;
    margin: 10px 0;
    background-color: rgba(0, 0, 0, 0.2);
}

.gu-transit {
  opacity: 0.2;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)";
  filter: alpha(opacity=20);
}
<script src="https://rawgit.com/bevacqua/angular-dragula/master/dist/angular-dragula.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="MainCtrl">
 <div class='wrapper'>
      <div class='container' id="container-one" dragula='"first-bag"'>
        <div>You can move these elements between these two containers</div>
        <div>Moving them anywhere else isn't quite possible</div>
        <div>There's also the possibility of moving elements around in the same container, changing their position</div>
      </div>
     <div class='container' id="container-two" dragula='"first-bag"'>
        <div>You can move these elements between these two containers</div>
        <div>Moving them anywhere else isn't quite possible</div>
        <div>There's also the possibility of moving elements around in the same container, changing their position</div>
      </div>
      <div class='container' id="container-third" dragula='"first-bag"'>
        <div>This is the default use case. You only need to specify the containers you want to use</div>
        <div>More interactive use cases lie ahead</div>
        <div>Make sure to check out the <a href='https://github.com/bevacqua/dragula#readme'>documentation on GitHub!</a></div>
      </div>
    </div>
  
  
</div>

最佳答案

var app = angular.module('angular-dragula-demo', [angularDragula(angular)]);


app.controller('MainCtrl', function($scope,$element, dragulaService) {
  dragulaService.options($scope, 'fisrt-bag', {
      copy: true
    });
     nameSpace: 'common';
});
.gu-mirror {
  position: fixed !important;
  margin: 0 !important;
  z-index: 9999 !important;
  opacity: 0.8;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=80)";
  filter: alpha(opacity=80);
}
.gu-hide {
  display: none !important;
}
.gu-unselectable {
  -webkit-user-select: none !important;
  -moz-user-select: none !important;
  -ms-user-select: none !important;
  user-select: none !important;
}
.gu-transit {
  opacity: 0.2;
  -ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=20)";
  filter: alpha(opacity=20);
}
body {
  background-color: #942A57;
  margin: 0 auto;
  max-width: 760px;
}

html, body {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

*, *:before, *:after {
  -webkit-box-sizing: inherit;
  -moz-box-sizing: inherit;
  box-sizing: inherit;
}

body, input, button {
  font-family: Georgia, Helvetica;
  font-size: 17px;
  color: #ecf0f1;
}

h1 {
  text-align: center;
  background-color: #AC5C7E;
  margin-top: 20px;
  margin-bottom: 0;
  padding: 10px;
}

h3 {
  background-color: rgba(255, 255, 255, 0.2);
  border-bottom: 5px solid #A13462;
  text-align: center;
  padding: 10px;
}

h3 div {
  margin-bottom: 10px;
}

.tagline {
  margin-top: 0;
}

.promo {
  margin-bottom: 0;
  font-style: italic;
  padding: 10px;
  background-color: #ff4020;
  border-bottom: 5px solid #c00;
}

a {
  font-weight: bold;
}
a,
a:hover {
  color: #ecf0f1;
}

pre {
  white-space: pre-wrap;
}

pre code {
  color: #fff;
  font-size: 14px;
  line-height: 1.3;
}

label {
  display: block;
  margin-bottom: 15px;
}

sub {
  display: block;
  margin-top: -10px;
  margin-bottom: 15px;
  font-size: 11px;
  font-style: italic;
}

ul {
  margin: 0;
  padding: 0;
}

.parent {
  background-color: rgba(255, 255, 255, 0.2);
  margin: 50px 0;
  padding: 20px;
}

input {
  border: none;
  outline: none;
  background-color: #ecf0f1;
  padding: 10px;
  color: #942A57;
  border: 0;
  margin: 5px 0;
  display: block;
  width: 100%;
}

button {
  background-color: #ecf0f1;
  color: #942A57;
  border: 0;
  padding: 18px 12px;
  margin-left: 6px;
  cursor: pointer;
  outline: none;
}

button:hover {
  background-color: #e74c3c;
  color: #ecf0f1;
}

.gh-fork {
  position: fixed;
  top: 0;
  right: 0;
  border: 0;
}

/* dragula-specific example page styles */
.wrapper {
  display: table;
}
.container {
  display: table-cell;
  background-color: rgba(255, 255, 255, 0.2);
  width: 50%;
}
.container:nth-child(odd) {
  background-color: rgba(0, 0, 0, 0.2);
}
/*
 * note that styling gu-mirror directly is a bad practice because it's too generic.
 * you're better off giving the draggable elements a unique class and styling that directly!
 */
.container div,
.gu-mirror {
  margin: 10px;
  padding: 10px;
  background-color: rgba(0, 0, 0, 0.2);
  transition: opacity 0.4s ease-in-out;
}
.container div {
  cursor: move;
  cursor: grab;
  cursor: -moz-grab;
  cursor: -webkit-grab;
}
.gu-mirror {
  cursor: grabbing;
  cursor: -moz-grabbing;
  cursor: -webkit-grabbing;
}
.container .ex-moved {
  background-color: #e74c3c;
}
.container.ex-over {
  background-color: rgba(255, 255, 255, 0.3);
}
.handle {
  padding: 0 5px;
  margin-right: 5px;
  background-color: rgba(0, 0, 0, 0.4);
  cursor: move;
}
<!DOCTYPE html>
<html ng-app="angular-dragula-demo">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <link rel="stylesheet" href="style.css" />
  </head>

  <body ng-controller="MainCtrl">
    <div class='wrapper'>
      <div class='container' id="con1" dragula='"bag-c"'>
        <div>You can move these elements between these two containers</div>
        <div>Moving them anywhere else isn't quite possible</div>
        <div>There's also the possibility of moving elements around in the same container, changing their position</div>
      </div>
      <div class='container' id="con2" dragula='"bag-b"'>
        <div>This is the default use case. You only need to specify the containers you want to use</div>
        <div>More interactive use cases lie ahead</div>
        <div>Make sure to check out the <a href='https://github.com/bevacqua/dragula#readme'>documentation on GitHub!</a></div>
      </div>
      <div class='container' id="con3" dragula='"bag-b"'>
        <div>This is the default use case. You only need to specify the containers you want to use</div>
        <div>More interactive use cases lie ahead</div>
        <div>Make sure to check out the <a href='https://github.com/bevacqua/dragula#readme'>documentation on GitHub!</a></div>
      </div>
      <div class='container' id="con4" dragula='"second-bag"'>
        <div>This is the default use case. You only need to specify the containers you want to use</div>
        <div>More interactive use cases lie ahead</div>
        <div>Make sure to check out the <a href='https://github.com/bevacqua/dragula#readme'>documentation on GitHub!</a></div>
      </div>
    </div>
    
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.7/angular.min.js"></script>
    <script src="https://rawgit.com/bevacqua/angular-dragula/master/dist/angular-dragula.min.js"></script>
    <script src="app.js"></script>
  </body>

</html>

也试试这个,它可能会帮助你打开这个链接 http://luckylooke.github.io/dragular/?utm_source=angular-js.in&utm_medium=website&utm_campaign=content-curation#/docs/exampleDifferentOptionsWithModel

关于javascript - 如何将项目从一个桶移动到另一个 - DragulaJS-Angular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39960525/

相关文章:

javascript - 如何使用带有 onclick 函数的 document.getElementsByClassName 覆盖样式

基于多个下拉选择的 Javascript 显示/隐藏 div

binding - AngularJS如何绑定(bind) map

angular - 使用 ng2-dragula 拖动和交换网格列表

javascript - dragula - 如何禁用在其父容器中的拖动

javascript - 使用加载更多按钮将所选类循环到 ul > li

javascript - 使用 AJAX 更新文本框

javascript - AngularJS 指令可以从动态内容中获取类名吗?

javascript - Angular js 模型值变化没有反射(reflect)在 ui 中

javascript - 使用 dragula 重新排序时如何保留对象属性?