Is there any event generated by continuous mouse click i.e., not releasing the mouse button 1? If no, please let me know.
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.
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 .
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With