1

I'm looking for a workaround for .mousemove() method on Chrome. It's a known issue.

Chrome keeps firing mousemove repeatedly even if the mouse is still.

I can't use .hover() method because the area is the window's height and width...

I think about checking the mouse cursor coordinates and check if they changed, but I really don't know where to start.

I reported to Chromium project: http://code.google.com/p/chromium/issues/detail?id=170631

flintsburg
  • 209
  • 2
  • 11
  • can you give a bit more explanation? or include your code? there are workarounds, but to give the best answer we need more context. – PlantTheIdea Jan 16 '13 at 17:02
  • Tony: here you go! http://jsfiddle.net/Q7HhT/ – flintsburg Jan 16 '13 at 17:45
  • just clarifying, since my french is weak ... u want the menu to show whenever the mouse is moving, and hide when not moving, correct? and btw, I'm using Chrome and your mousemove function is working as expected. – PlantTheIdea Jan 16 '13 at 17:47
  • Yes, you have it right. Expected behavior: > cursor is not moving on #main > #menu hide which is OK sor far. But if you keep your cursor still, at some point - at least on my working environment - the menu shows again at some point. – flintsburg Jan 16 '13 at 17:58
  • Indeed, what I did work well on my other computer... – flintsburg Jan 16 '13 at 20:39
  • I reported the bug http://code.google.com/p/chromium/issues/detail?id=170631 – flintsburg Jan 17 '13 at 14:06
  • I had some similar issues with Chrome blasting off multiple mousemoves while the other browsers worked fine. Try running the code at the bottom of this link to track your mouse, see if it is moving when not moving, [JQuery .mouseover](http://api.jquery.com/mousemove/) PS. I know this isn't answer, I don't know how to post comments under the questions:-( – ChrisWilson4 Jan 16 '13 at 17:14

1 Answers1

0

Still got the Problem in Chrome Version 29.0.1547.66 m and searched for a "real" solution. Nothing found so far. Like you said, i start to write a function to check if the mouse are really moved or not.

Specially, you can change some settings for your own needs.

var my_mouseMovements = {
    readNewPos : true, //indicates if time since last check are elapsed
    oldPos : [0,0], //pos from the last check
    minX_Distance: 10, //only look at movements thats are big enough(px)
    minY_Distance: 10, //only look at movements thats are big enough(px)
    timeBetweenEachCheck : 100, //Just checking every x ms for movements
    saveNewPos : function(pos,callback){
    if(this.readNewPos === true)
    {
        this.readNewPos = false;


        var xDistance = pos[0] - this.oldPos[0];
        var yDistance = pos[1] - this.oldPos[1];
        //Just making the distances positive
        xDistance = xDistance < 0 ? -xDistance : xDistance;
        yDistance = yDistance < 0 ? -yDistance : yDistance;

        //Check if mouse moved more then expected distance
        if(xDistance >=  this.minX_Distance || yDistance >= this.minY_Distance)
        {
            console.log("Mouse has moved a lot since last check!");
            if(callback !== undefined)
            {
                callback();
            }
        }

        this.oldPos = pos;

        var that = this;
        //reset readNewPos after a while
        setTimeout(function(){
            that.readNewPos = true;
        },this.timeBetweenEachCheck);
    }
    else //Just for debug right now
    {
        console.log("the last time was not far away");
    }
}
};

jQuery('body').mousemove(function(e){
    my_mouseMovements.saveNewPos([e.pageX,e.pageY]);
});
basis
  • 158
  • 2
  • 8