Angular JS Long Press活动

时间:2016-02-18 13:57:15

标签: javascript angularjs

如何长按" +"持续增加价值按下" - "继续减少请帮忙。

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.count = 0;

请参阅http://plnkr.co/edit/3lpyqPPdAyXJOIMxM47V?p=preview

1 个答案:

答案 0 :(得分:0)

要进行连续递增,您可以启动一个间隔,该间隔将触发mouserdown事件的递增,并在mouseup上清除它。

app.controller('myCtrl', function($scope) {
  $scope.count = 0;
  var interval;
  $scope.start = function(direction) {
    interval = setInterval(function() {
      if(direction == 1) 
        $scope.count++;
      else
      $scope.count--;

      $scope.$apply();  
    }, 100);
  }

  $scope.clear = function() {
    clearInterval(interval); 
  }

});


<h1 ng-mouseup="clear()" ng-mousedown="start(1)">+</h1>
<h1 ng-mouseup="clear()" ng-mousedown="start(0)">-</h1>

http://plnkr.co/edit/u7HA1XzbkdvGe3r2KEuH?p=preview