1

我正在寻找 Chrome 上 .mousemove() 方法的解决方法。这是一个已知问题。

即使鼠标静止,Chrome 也会不断触发 mousemove。

我不能使用 .hover() 方法,因为该区域是窗口的高度和宽度......

我考虑检查鼠标光标坐标并检查它们是否改变,但我真的不知道从哪里开始。

我向 Chromium 项目报告: http ://code.google.com/p/chromium/issues/detail?id=170631

4

1 回答 1

0

仍然在 Chrome 版本 29.0.1547.66 m 中遇到问题并寻找“真正的”解决方案。到目前为止没有发现任何东西。就像你说的,我开始编写一个函数来检查鼠标是否真的移动了。

特别是,您可以根据自己的需要更改一些设置。

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]);
});
于 2013-09-26T13:28:51.250 回答