Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果我点击并按住按钮,如何使用angular反复启动鼠标点击按钮?_Javascript_Jquery_Angularjs - Fatal编程技术网

Javascript 如果我点击并按住按钮,如何使用angular反复启动鼠标点击按钮?

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">

我怎样才能在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"></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>