gpt4 book ai didi

javascript - Angular 拖放不适用于移动设备

转载 作者:可可西里 更新时间:2023-11-01 02:41:52 26 4
gpt4 key购买 nike

我正在使用这个 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 所述:

The biggest issue with mobile is rewriting the handlers to work with the various touch events. It should be doable, but I haven't attempted.


尝试调整它会浪费您的时间。不过,还有其他支持触摸事件的拖放指令。您可以查看:

备选方案:

angular-dragdrop

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

ngDraggable

简单且适用于移动设备。您可以看到一个触摸启用示例 here .

ng-sortable

适用于移动设备。您可以看到触摸启用示例 here .

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com