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
To make continuously incrementation you can start an interval which will trigger incrementation on mouserdown
event, and clear it on 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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.