gpt4 book ai didi

javascript - Angular JS 长按事件

转载 作者:行者123 更新时间:2023-11-28 06:21:34 25 4
gpt4 key购买 nike

如何长按“+”连续增加数值,按“-”连续减少数值,请帮忙。

var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.count = 0;

请参阅http://plnkr.co/edit/3lpyqPPdAyXJOIMxM47V?p=preview

最佳答案

要连续增量,您可以启动一个间隔,该间隔将在 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>

http://plnkr.co/edit/u7HA1XzbkdvGe3r2KEuH?p=preview

关于javascript - Angular JS 长按事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35483434/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com