0

I want to know the name of the mouse event when It is keep pressing without releasing it.I know about mousedown, mouseclick.

I want to perform different - different action on both the events.One action on mouseclick and another when mouse is pressed withour releasing.

Bhuvnesh Gupta
  • 91
  • 1
  • 3
  • 7
  • 2
    Why not using mousedown? If you are looking for just styling, there is also CSS pseudo class ':active'. Or please elaborate on what you are looking for... – A. Wolff Jul 08 '13 at 12:36
  • Almost the same issue: http://stackoverflow.com/questions/7163642/javascript-long-click-for-a-bookmarklet It is not an event though... – Balint Bako Jul 08 '13 at 12:36
  • 1
    Possible duplicate: [JavaScript while mousedown](http://stackoverflow.com/q/15505272/1456376) – insertusernamehere Jul 08 '13 at 12:37
  • I want to perform some actions inside these two events and mousedown is not the solution.I want action when mouse is pressed and not released – Bhuvnesh Gupta Jul 08 '13 at 12:38
  • Mousedown is not a solution for what? We still don't know what you are looking for??? – A. Wolff Jul 08 '13 at 12:39

3 Answers3

1

If you need an event to trigger after holding an element for some time you could use the .mousedown event and then use setTimeout to run the function with a delay. You should bind a clear timer function to the mouseup event.

DreamWave
  • 1,934
  • 3
  • 28
  • 59
0

It still sounds like you're looking for .mousedown()

http://api.jquery.com/mousedown/

To clarify: If you want some code to execute repeatedly until the mouse is released (I can't quite tell if that's actually what you want), you could use something like this:

var interval = -1;

function doThing(){
    console.log("this will execute 10 times per second while the mouse is held down");
}

$('#element').mousedown(function(){
    if(interval !== -1)
        clearInterval(interval);
    interval = setInterval(doThing, 100);
});

$('#element').mouseup(function(){
    if(interval !== -1)
        clearInterval(interval);
});
Dan Hlavenka
  • 3,697
  • 8
  • 42
  • 60
0

I guess you are looking for MouseHold event .

Here is a light weight plugin for that.

Here you can use the open source code to get the things done.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307