admin管理员组文章数量:1194384
I have made a time conter which allows you to increase or decrease the time by clicking a button. I would like however that when I click and hold the button the value of the time would keep climbing.
So currently if you see my Plunkr each time I click the up button the value increases but I want this so when I hold the button down the value increases 1,2,3,4,5,6,7,8
until I release the button.
How could I achieve something like this?
I have made a time conter which allows you to increase or decrease the time by clicking a button. I would like however that when I click and hold the button the value of the time would keep climbing.
So currently if you see my Plunkr each time I click the up button the value increases but I want this so when I hold the button down the value increases 1,2,3,4,5,6,7,8
until I release the button.
How could I achieve something like this?
Share Improve this question edited Aug 16, 2014 at 0:04 Darshan P 2,24119 silver badges16 bronze badges asked Aug 7, 2014 at 10:37 DaimzDaimz 3,28114 gold badges51 silver badges77 bronze badges1 Answer
Reset to default 25DEMO
<span class="time">{{ Time | timeFilter }}</span>
<div class="btn-group btn-group-sm">
<button class="btn btn-default" ng-mousedown='mouseDown()' ng-mouseup="mouseUp()">
<i class="fa fa-caret-up"></i>
</button>
<button class="btn btn-default" ng-click="Time = Time - 1">
<i class="fa fa-caret-down"></i>
</button>
</div>
Use ng-mouseDown and ng-mouseup directive with $interval
app.directive('time', function ($interval) {
return {
templateUrl: 'time.html',
restrict: 'E',
scope: {
Time: '=value'
},
link: function (scope, element, attrs) {
element.addClass('time');
var promise;
scope.mouseDown = function() {
if(promise){
$interval.cancel(promise);
}
promise = $interval(function () {
scope.Time++;
}, 100);
};
scope.mouseUp = function () {
$interval.cancel(promise);
promise = null;
};
}
};
});
本文标签: javascriptHow can I listen for a clickandhold in AngularJSStack Overflow
版权声明:本文标题:javascript - How can I listen for a click-and-hold in AngularJS? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738500746a2090254.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论