Jquery:mousedown效果(左击时按住) [英] Jquery: mousedown effect (while left click is held down)
本文介绍了Jquery:mousedown效果(左击时按住)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个函数,当按钮被按下时执行函数,当按钮被放开时停止执行
I need a function that executes a function while a button is pressed and stops executing when the button is let go
$('#button').--while being held down--(function() {
//execute continuously
});
推荐答案
我相信这样会有效:
var timeout, clicker = $('#clicker');
clicker.mousedown(function(){
timeout = setInterval(function(){
// Do something continuously
}, 500);
return false;
});
$(document).mouseup(function(){
clearInterval(timeout);
return false;
});
查看此演示:http://jsfiddle.net/8FmRd/
See this demo: http://jsfiddle.net/8FmRd/
这篇关于Jquery:mousedown效果(左击时按住)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文