pio*_*ion 16 javascript jquery
我有以下代码片段
$(document).mousedown(function(event) {
doSomething();
}
Run Code Online (Sandbox Code Playgroud)
我可以mousedown成功捕获事件.
我正在尝试执行以下操作:
mousedown事件Ric*_*iwi 26
就像是
var mouseStillDown = false;
$(document).mousedown(function(event) {
mouseStillDown = true;
doSomething();
});
function doSomething() {
if (!mouseStillDown) { return; } // we could have come back from
// SetInterval and the mouse is no longer down
// do something
if (mouseStillDown) { setInterval("doSomething", 100); }
}
$(document).mouseup(function(event) {
mouseStillDown = false;
});
Run Code Online (Sandbox Code Playgroud)
小智 20
var int00; // declared here to make it visible to clearInterval.
$('#trigger').mousedown(function(){
int00 = setInterval(function() { repeatingfunction(); }, 50);
}).mouseup(function() {
clearInterval(int00);
});
function repeatingfunction() {
// This will repeat //
}
Run Code Online (Sandbox Code Playgroud)
你也可以clearInterval参加mouseleave活动.
你实现了一些递归!
var mouseisdown = false;
$(document).mousedown(function(event) {
mouseisdown = true;
doSomething();
}).mouseup(function(event) {
mouseisdown = false;
});
function doSomething(){
//Code goes here
if (mouseisdown)
doSomething();
}
Run Code Online (Sandbox Code Playgroud)