我正在寻找Chrome上的.mousemove()方法的解决方法。这是一个众所周知的问题。
即使鼠标静止,Chrome仍会反复触发鼠标移动。
我不能使用.hover()方法,因为该区域是窗口的高度和宽度......
我考虑检查鼠标光标坐标并检查它们是否发生了变化,但我真的不知道从哪里开始。
我向Chromium项目汇报: http://code.google.com/p/chromium/issues/detail?id=170631
答案 0 :(得分: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]);
});