[英]Angular JS Long Press event
How to increase value continuously on long press of "+" and decrease continuously on press on "-" please help. 如何在长按“ +”时连续增加值,并在长按“-”时连续减少值,请提供帮助。
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.count = 0;
Please see http://plnkr.co/edit/3lpyqPPdAyXJOIMxM47V?p=preview 请参阅http://plnkr.co/edit/3lpyqPPdAyXJOIMxM47V?p=preview
To make continuously incrementation you can start an interval which will trigger incrementation on mouserdown
event, and clear it on mouseup
. 要进行连续递增,您可以启动一个间隔,该间隔将在
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 http://plnkr.co/edit/u7HA1XzbkdvGe3r2KEuH?p=preview
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.