Javascript 如果我点击并按住按钮,如何使用angular反复启动鼠标点击按钮?
我怎样才能在500毫秒的间隔后反复调用控制器中的旋转功能,直到用户单击并按住按钮?使用ng mousedown和ng mouseup directie interval服务的组合,您可以创建此功能Javascript 如果我点击并按住按钮,如何使用angular反复启动鼠标点击按钮?,javascript,jquery,angularjs,Javascript,Jquery,Angularjs,我怎样才能在500毫秒的间隔后反复调用控制器中的旋转功能,直到用户单击并按住按钮?使用ng mousedown和ng mouseup directie interval服务的组合,您可以创建此功能 <button type="button" class="btn btn-default" ng-click="rotate(true)"> <i class="fa fa-sort-asc" style="color:blue">
<button type="button" class="btn btn-default"
ng-click="rotate(true)">
<i class="fa fa-sort-asc" style="color:blue"></i>
</button>
在startrotate函数中,创建一个间隔,该间隔每x次调用一次rotate函数。在endRotate中,根据在start函数中创建的间隔调用cancel函数
编辑:您还需要ng mouseleave,因为如果在鼠标按钮按下时将鼠标从按钮上移开,则ng mouseup将永远不会注册
文件:
$interval您可以使用setInterval在固定时间间隔调用特定函数,您比我快:(这是我为…演示准备的一个很好的示例,但使用您的示例,我发现您还需要ng mouseleave。我更改了您的示例以演示:
<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>