Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous mouse click event

Is there any event generated by continuous mouse click i.e., not releasing the mouse button 1? If no, please let me know.

like image 218
Tapas Bose Avatar asked Jul 06 '11 12:07

Tapas Bose


People also ask

How do I trigger mouse click event?

click() method simulates a mouse click on an element. When click() is used with supported elements (such as an <input> ), it fires the element's click event. This event then bubbles up to elements higher in the document tree (or event chain) and fires their click events.

Which are the mouse click event?

The MouseEvent interface represents events that occur due to the user interacting with a pointing device (such as a mouse). Common events using this interface include click , dblclick , mouseup , mousedown . MouseEvent derives from UIEvent , which in turn derives from Event .

What is Onmousedown in Javascript?

Definition and Usage The onmousedown event occurs when a user presses a mouse button over an element. Tip: The order of events related to the onmousedown event (for the left/middle mouse button): onmousedown. onmouseup.

How do you know if an event is clicking?

To check if an element was clicked, add a click event listener to the element, e.g. button. addEventListener('click', function handleClick() {}) . The click event is dispatched every time the element is clicked. Here is the HTML for the examples in this article.


2 Answers

The mousedown event is triggered when the mouse button is pressed down. If you are looking for an event that fires repeatedly, while the button is held down, you are out of luck, but you can use the mousedown event to repeatedly perform an action, and stop when the mouseup event is triggered.

For example, you could use the setInterval function to repeatedly call a function while the mouse button is down, and then use clearInterval to stop when the mouse button is released. Here is an example (using jQuery):

var interval;
$("#elementToClick").mousedown(function() {
    interval = setInterval(performWhileMouseDown, 100);
}).mouseup(function() {
    clearInterval(interval);  
});
function performWhileMouseDown() {
    $("#output").append("<p>Mouse down</p>");
}

You can see this running in this example fiddle.

like image 163
James Allardice Avatar answered Oct 15 '22 00:10

James Allardice


There is a JQuery plugin: LongClick

Longclick is press & hold mouse button "long click" special event for jQuery 1.4.x.

The event is triggered when the mouse button stays pressed for a (configurable) number of seconds, while the pointer is stationery.

like image 24
painotpi Avatar answered Oct 14 '22 23:10

painotpi