Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

listen to mouse hold event on website?

I know 'mousedown' is when user press the mouse, 'mouseup' is when user release the mouse. But I want to listen the event after user press the mouse and hold it until it release. Any ideas?

like image 418
user2268624 Avatar asked Sep 03 '13 05:09

user2268624


1 Answers

If you want the hold state then it will be the state when you are in mousedown event state for a while. This state exists when you press mousedown but not mouseup. Hence you need to take a variable which records the current state of the event.

JS

$('div').on('mousedown mouseup', function mouseState(e) {
    if (e.type == "mousedown") {
        //code triggers on hold
        console.log("hold");
    }
});

Working Fiddle

like image 110
Mr_Green Avatar answered Oct 05 '22 18:10

Mr_Green