我正在使用这个lvlDragDrop plugin。它不能在移动平台上运行。
他们在github上添加了这个issue。但是我还是没有运气。

Github Demo

HTML

<div ng-controller="ddController" style="margin-top:50px;">
            <div class="row">
                <div class="col-md-1 col-md-offset-1">
                    <p>Click and drag a color onto the grid to the right</p>
                    <div class="peg green" x-lvl-draggable="true" data-color="green">Green</div>
                    <div class="peg red" x-lvl-draggable="true" data-color="red">Red</div>
                    <div class="peg blue" x-lvl-draggable="true" data-color="blue">Blue</div>
                    <div class="peg black" x-lvl-draggable="true" data-color="black">Black</div>
                    <div class="peg grey" x-lvl-draggable="true" data-color="grey">Grey</div>
                </div>

                <div class="col-md-10">
                    <div ng-repeat="r in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]">
                        <span class="slot circle" ng-repeat="c in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]" x-lvl-drop-target="true" x-on-drop="dropped(dragEl, dropEl)"></span>
                    </div>
                </div>
            </div>
        </div>

JS
angular.module('ddApp', ['lvl.directives.dragdrop']) // register the directive with your app module
            .controller('ddController', ['$scope' , function($scope){
                $scope.dropped = function(dragEl, dropEl) { // function referenced by the drop target
                    //this is application logic, for the demo we just want to color the grid squares
                    //the directive provides a native dom object, wrap with jqlite
                    var drop = angular.element(dropEl);
                    var drag = angular.element(dragEl);

                    //clear the previously applied color, if it exists
                    var bgClass = drop.attr('data-color');
                    if (bgClass) {
                        drop.removeClass(bgClass);
                    }

                    //add the dragged color
                    bgClass = drag.attr("data-color");
                    drop.addClass(bgClass);
                    drop.attr('data-color', bgClass);

                    //if element has been dragged from the grid, clear dragged color
                    if (drag.attr("x-lvl-drop-target")) {
                        drag.removeClass(bgClass);
                    }
                }
            }]);

最佳答案

该指令不支持触摸屏。如GitHub所述:



尝试进行调整会浪费您的时间。但是,还有其他拖放指令支持触摸事件。您可以 checkout :

替代方法:

angular-dragdrop

可能最有名。这是some examples。请注意,它们不适用于触摸设备。为了支持触摸事件,您还应该添加touchpunch.js

ngDraggable

简单,可在移动设备上使用。您可以看到启用触摸的示例here

ng-sortable

在移动设备上工作。您可以看到启用触摸的示例here

关于javascript - Angular 拖放在移动设备上不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39347071/

10-10 15:25