0

I have a below situation.

function mousemove(e){
if(left button clicked){
//drag the element
}
else{
//show the tooltip
}
}

Initially i have binded the mousemove function. while mouse moving i need to check whether the left button is clicked or not. if clicked means i need to drag it. else means i need to show tooltip.

i searched a lot. i cant get the solution for all the browser, I need to do this for IE8,IE9,IE10,IE11,Chrome, firefox and safari. please help me... thanks in advance..

Srinivasan
  • 69
  • 1
  • 1
  • 6
  • Set dragging flag on `mousedown`, remove on `mouseup`. On `mousemove` drag if flag is `on`. Than your condition would be `if(flag){ ...drag... }` – skobaljic Dec 10 '14 at 13:55

1 Answers1

1

The event itself does not tell you if the button is being held, so you have to track it yourself using mousedown and mouseup, something like this:

var clickHeld = false;
$('#myElement').on({
    'mousemove': function() {
        if (clickHeld) {
            // a click & drag is happening, do what you require
        }
    },
    'mousedown': function() { clickHeld = true; },
    'mouseup': function() { clickHeld = false; }
});
Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339