[英]how can I fire the mouse click button again and again using angular if I click and hold a button?
<button type="button" class="btn btn-default"
ng-click="rotate(true)">
<i class="fa fa-sort-asc" style="color:blue"></i>
</button>
How can I call the rotate function in my controller again and again after an interval of say 500 msec until the user clicks and holds the button? 在间隔500毫秒之后直到用户单击并按住按钮后,如何在控制器中一次又一次调用Rotate函数?
With a combination of the ng-mousedown and ng-mouseup directie interval service you can create this functionality. 结合使用ng-mousedown和ng-mouseup Directie interval服务,您可以创建此功能。
<button type="button" class="btn btn-default"
ng-mousedown="startRotate(true)" ng-mouseup="endRotate()" ng-mouseleave="endRotate()" >
<i class="fa fa-sort-asc" style="color:blue"></i>
</button>
in the startrotate function you create an interval that calls the rotate function every x time. 在startrotate函数中,您将创建一个间隔,该间隔每x次调用一次rotate函数。 In the endRotate you call the cancel function on the interval you created in the start function. 在endRotate中,您在启动函数中创建的间隔上调用取消函数。
Edit: you also need ng-mouseleave because the ng-mouseup is never registered if you move the mouse off the button while the mouse button is down. 编辑:您还需要ng-mouseleave,因为如果在鼠标按钮按下时将鼠标从按钮上移开,则ng-mouseup不会被注册。
Documentation: 说明文件:
http://docs.angularjs.org/api/ng/directive/ngMousedown http://docs.angularjs.org/api/ng/directive/ngMousedown
http://docs.angularjs.org/api/ng/directive/ngMouseup http://docs.angularjs.org/api/ng/directive/ngMouseup
http://docs.angularjs.org/api/ng/service/ $interval http://docs.angularjs.org/api/ng/service/ $ interval
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.