[英]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.