我有一个项目列表,当我将手指移到每个项目上时,我想获取每个项目的 ID。它适用于鼠标,但不适用于触摸。我正在使用这个库:https ://github.com/nglar/ngTouch
HTML:
<p class="text-center" > item : {{current}}</p>
<p class="text-center" > state : {{state}}</p>
<div class="row" ng-repeat="item in items" >
<div ng-style="{background: color}"
style="width:100px;height:100px;margin-top:10px;margin-left:auto;margin-right:auto"
ng-touchstart="onTouchstart(item)"
ng-touchmove="onTouchmove(item)"
ng-touchend="onTouchend(item)">
<p>{{item}}</p>
</div>
</div>
JS:
$scope.items = ["1" , "2" , "3"];
$scope.current = "0";
$scope.state = "waiting..."
$scope.color = "red";
$scope.onTouchstart = function(item) {
$scope.current = item;
$scope.state = "Touch start"
}
$scope.onTouchmove = function(item) {
$scope.current = item;
$scope.state = "Touch move"
}
$scope.onTouchend = function(item) {
$scope.current = item;
$scope.state = "Touch end"
}
如果我在当前元素中,它工作正常,它检测到 3 个动作。但是例如,当我触摸第 1 项并将手指移动到第 2 项时,它没有检测到它,它仍然在第 1 项上。