JQuery隐藏鼠标,如果它没有移动 [英] JQuery hide mouse if it's not moving

查看:201
本文介绍了JQuery隐藏鼠标,如果它没有移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我使用的代码:

  $(document).ready(function(){
var j;
$(document).mousemove函数(){
clearTimeout(j);
$('html')。css({cursor:'default'});
j = setTimeout('hide();',1000 );
});
});

function hide(){
$('html')。css({cursor:'none'});

当hide()函数被调用时,游标被隐藏,但是取消隐藏稍后再分。任何帮助表示赞赏。

解决方案

最初的问题是鼠标的隐藏触发 mousemove ,并立即将其重置为默认值。所以你可以像这样解决...

  var justHidden = false; 
$ b $(document).ready(function(){
var j;
$(document).mousemove(function(){
if(!justHidden) {
justHidden = false;
console.log('move');
clearTimeout(j);
'('html')。css({{cursor:'default' });
j = setTimeout('hide();',1000);
}
});
});

function hide(){
$('html')。css({cursor:'none'});
justHidden = true;
}



... BUUUUUT ...



您面临的问题目前似乎无法解决。也就是说,一个隐藏的鼠标不会触发 mousemove 有史以来,所以一旦它被隐藏,你将无法取消隐藏它,据我所知。



我会继续调查,看看是否有我缺少的解决方案。


I'm trying to hide the mouse if it hasn't moved for a period of time.

This is the code I'm using:

$(document).ready(function() {
    var j;
    $(document).mousemove(function() {
        clearTimeout(j);
        $('html').css({cursor: 'default'});
        j = setTimeout('hide();', 1000);
    });
});

function hide() {
    $('html').css({cursor: 'none'});
}

When the hide() function is called the cursor is hidden, but unhides a split second later. Any help is appreciated.

解决方案

Your initial problem is that the hiding of the mouse triggers mousemove and thus immediately resets it back to default. So you could solve that like this...

var justHidden = false;

$(document).ready(function() {
    var j;
    $(document).mousemove(function() {
        if (!justHidden) {
            justHidden = false;
            console.log('move');
            clearTimeout(j);
            $('html').css({cursor: 'default'});
            j = setTimeout('hide();', 1000);
        }
    });
});

function hide() {
    $('html').css({cursor: 'none'});
    justHidden = true;
}​

...BUUUUUT...

You face a problem here which at the moment seems unsolvable to me. That is, a hidden mouse does not trigger mousemove ever, so once it's hidden you will not be able to unhide it as far as I can tell.

I'll keep investigating to see if there's a solution I'm missing.

这篇关于JQuery隐藏鼠标,如果它没有移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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