如何长按" +"持续增加价值按下" - "继续减少请帮忙。
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.count = 0;
答案 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>