簡體   English   中英

Angular JS長按事件

[英]Angular JS Long Press event

如何在長按“ +”時連續增加值,並在長按“-”時連續減少值,請提供幫助。

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

請參閱http://plnkr.co/edit/3lpyqPPdAyXJOIMxM47V?p=preview

要進行連續遞增,您可以啟動一個間隔,該間隔將在mouserdown事件觸發時觸發增量,並在mouseup事件mouserdown其清除。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM