Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
124
rated 0 times [  125] [ 1]  / answers: 1 / hits: 26066  / 14 Years ago, thu, february 10, 2011, 12:00:00

I have the following code snippets



$(document).mousedown(function(event) {
doSomething();
}


I can capture the mousedown event successfully.



I am trying to do the following:




  1. Capture the first mousedown event

  2. I want to detect if the user is still holding the mouse down so I can do something else.


More From » jquery

 Answers
7

Something like



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;
});

[#93795] Wednesday, February 9, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
denver

Total Points: 232
Total Questions: 111
Total Answers: 103

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
;