[英]Angular JS Long Press event
如何在长按“ +”时连续增加值,并在长按“-”时连续减少值,请提供帮助。
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.count = 0;
要进行连续递增,您可以启动一个间隔,该间隔将在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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.