1

I notice in the jsfiddle here -http://jsfiddle.net/6NLsm/1/ - that clicking in the beige box causes an entry into the mousemove handler. How is a click considered to be a mousemove?

Thanks

$(function() {
    $('body').mousemove(function(e){
        console.log("mousemove hander: x="+e.clientX+",y="+e.clientY);
    });
});
Steve
  • 4,534
  • 9
  • 52
  • 110

2 Answers2

1

Seems a bug related to Chrome (mmmh or JQuery), try this in IE10 and no mousemove event are triggered on mouseclick

$(function() {
    $('body').mousemove(function(e){
        //console.log("mousemove hander: x="+e.clientX+",y="+e.clientY);

        console.log(e.type);
    });
});

without Jquery

var p = document.getElementById('box');
p.onmousemove = function () {
    //debugger;
    console.log(arguments[0].type);
};
ale
  • 10,012
  • 5
  • 40
  • 49
  • @Steve what do you think about this? – ale Jun 01 '14 at 09:20
  • Yes, this looks like a Chrome bug. A left click gets sent to the Chrome mouseover handler with e.type = mousemove. The mousemove handler in IE and Firefox doesn't see a left click event. – Steve Jun 01 '14 at 12:59
0

I see entries when I move the mouse; however, not when I click. I would guess that when you click you are causing a mouse movement that, while barely perceptible to you is perceptible to the computer which is accurate to detect movement on the pixel level. As @Amit Joki points out in his response you can programmatically ignore clicks in the event that you do make a slight movement while clicking.

mifi79
  • 1,086
  • 6
  • 8
  • What I want to know in the handler is whether or not a move occurred. Did the user just click something, or did they click and drag? – Steve Jun 01 '14 at 06:28
  • 1
    @Steve Check out this SO, I think it will get you what you are looking for: http://stackoverflow.com/questions/4127118/can-you-detect-dragging-in-jquery – mifi79 Jun 01 '14 at 06:41