简体   繁体   English

如果单击并按住一个按钮,如何使用angular一次又一次触发鼠标单击按钮?

[英]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.

相关问题 当我单击制作排序(ab)数组然后再次单击排序(ba)时,如何制作单击按钮 - How can i make a click button when do i click make sort(a-b) array and then click again to sort(b-a) 我怎样才能制作一个按钮保持聚焦的CSS样式,直到我再次点击它 - How can I make a button keep the focused css style till I click on it again 单击按钮后如何显示下一张卡片并再次单击并再次显示下一张卡片到最后一张卡片并提交 jquery? - How I can showing the next card after clicking button and click again and show next card again to last card and submit with jquery? 我怎样才能做到这一点当我点击一个按钮时它会解析一个 promise,如果我再次点击它会等到之前的 promise 被解析 - How can i make so when i click a button it will resolve a promise, and if i click again it will wait untill the previous promise is resolved 当我单击按钮查看测验时,它保持在 0 但如果您再次单击它,它会在每次按下它时一次又一次地求和 - When I click the button to review the quizz it stays in 0 but if you click it again it sum the score again and again each time you press it 单击时我想显示按钮,再次单击时我想隐藏一个按钮 - On Click i want to show button and again on click i want to hide a button 如何在单击按钮时触发带有钩子和 Redux 的 API 调用 - How can i fire an API call with hooks and Redux on button click 如何再次绑定按钮的click事件 - how to bind again the click event for the button 再次单击按钮后如何显示警报? - How to show alert after click the button again? 如何在按钮点击反应时再次调用useEffect? - How to call useEffect again on button click in react?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM