首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多元素拖放

多元素拖放
EN

Stack Overflow用户
提问于 2016-11-14 18:32:50
回答 2查看 1.5K关注 0票数 1

我正在为我的客户做拖放功能。我已经为拖放实现了拖放,但是在dragular或任何其他为拖放提供的库中没有提供多元素拖放。

请建议我如何选择和拖放多个元素在角或任何其他javascript库,也应该与触摸设备兼容。

提前谢谢。

注:我们可以使用拖曳多次拖放。?

更新(30/11/2016):把我的要求加起来一点。如何限制拖放区域中元素的冗余。

解释:

  • 当我们从源复制任何项目时,如果它已经被拖放到/在目标容器中,我们将无法拖动它。
  • 准确地说,如果物品已经在目标容器中,我们可以使它们不被拖拽。
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-15 16:43:21

你的意思是多个单独的拖放?就像用一个手指拉一个元素,用另一个手指拉第二个元素?

这不是dragula支持的,也不是dragular支持的,但我正在开发新的库,这是可能的,但它现在仍在进行中:/

我不知道还有其他图书馆支持它。

编辑(27.11.16):

我更新了你的钢笔http://codepen.io/luckylooke/pen/zodmEO

代码语言:javascript
复制
angular.module("testDnD", ["dragularModule"]).
controller("test", ['$scope', 'dragularService', function($scope, dragularService) {

  $scope.selected = [];
  $scope.filter = [];
  $scope.testObj = [{...}];

  $scope.modelClickData = function(test) {
    console.log(test);
    $scope.popdata = test;
  };

  $scope.modelSelect = function(test) {
    test.selected = !test.selected;

    if (test.selected)
      $scope.selected.push(test);
    else
      $scope.selected.splice($scope.selected.indexOf(test), 1);

    // console.log('selected', test);
  };

  var containerLeft = document.querySelector('#thumbnailTST');
  var containerRight = document.querySelector('#filler');

  dragularService.cleanEnviroment();
  dragularService([containerLeft, containerRight], {
    copy: true,
    containersModel: [$scope.testObj, $scope.filter],
    scope: $scope
  });

  $scope.$on('dragularcloned', function() {
    var mirror = $('.gu-mirror');
    if ($scope.selected.length > 1 && mirror.length) { // is multiple drag
      mirror.addClass('multipledrag');
    }
  });

  $scope.$on('dragulardrop', function(e, el, targetcontainer, sourcecontainer, conmodel, elindex, targetmodel, dropindex) {
    if ($scope.selected.length > 1) { // is multiple drag
      $scope.selected.forEach(function(item) {
        if (item != $scope.testObj[elindex]) {
          var clone = {};
          clone = $.extend(true, clone, item);
          delete clone.$$hashKey;
          $scope.filter.splice(++dropindex, 0, clone);
        }
      });
    }
    console.log($scope.filter);
  });

}])
票数 0
EN

Stack Overflow用户

发布于 2016-11-14 18:46:39

这是你问题的答案。jQuery Sortable - Select and Drag Multiple List Items

我认为使用jQuery进行拖放是个好主意。我用的是这个而且是工作的。这里你有个例子

jsfiddle.net/hQnWG/614/

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40595459

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档