gpt4 book ai didi

javascript - 如何停止ngDraggable Angular js中的点击事件?

转载 作者:行者123 更新时间:2023-12-03 07:05:16 26 4
gpt4 key购买 nike

我有一些带有链接的可拖动面板。我想在拖动它们时停止单击事件。每次我放下图 block 时,它都会到达该地址。我使用 ngDraggable.js 。我尝试使用 e.preventDefault() 和 e.stopPropagation() 但没有成功。

angular.module('ExampleApp', ['ngDraggable']).
controller('MainCtrl', function ($scope) {
$scope.draggableObjects = [
{name: 'one'},
{name: 'two'},
{name: 'three'}
];
$scope.onDropComplete = function (index, obj, evt) {
var otherObj = $scope.draggableObjects[index];
var otherIndex = $scope.draggableObjects.indexOf(obj);
$scope.draggableObjects[index] = obj;
$scope.draggableObjects[otherIndex] = otherObj;
evt.stopPropagation();
evt.preventDefault();
}
});

html

<div class="row text-center" ng-controller="MainCtrl">
<ul class="draglist">
<li ng-repeat="obj in draggableObjects" ng-drop="true" ng-drop-success="onDropComplete($index, $data,$event)">
<div ng-drag="true" ng-drag-data="obj" ng-class="obj.name">
{{obj.name}}
</div>
</li>
</ul>
</div>

最佳答案

在onClick/ng-click中添加event.preventDefault和event.stopPropagation

关于javascript - 如何停止ngDraggable Angular js中的点击事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36851343/

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