jQuery mousemove解决方法 [英] jQuery mousemove workaround

查看:120
本文介绍了jQuery mousemove解决方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

即使鼠标仍然存在,Chrome仍会反复发出鼠标移动。

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

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

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.



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

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



推荐答案

Chrome版本29.0.1547.66米出现问题,并搜索真实解决方案。迄今没有发现。
就像你说的,我开始编写一个函数来检查鼠标是否真的被移动。

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]);
});

这篇关于jQuery mousemove解决方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆