Hide div element with jQuery, when mouse isn't moving for a period of time?

前端 未结 1 1761
花落未央
花落未央 2021-02-05 18:09

I have a broadcasting video site, with a menu, which should be hidden, when mouse isn\'t moving for a while (lets say 10 seconds). As well, it should appears back, with mouse mo

相关标签:
1条回答
  • 2021-02-05 18:39

    Take a look at the mousemove event. You can try something like this:

    var i = null;
    $("#element").mousemove(function() {
        clearTimeout(i);
        $("#menu").show();
        i = setTimeout(function () {
            $("#menu").hide();
        }, 10000);
    }).mouseleave(function() {
        clearTimeout(i);
        $("#menu").hide();  
    });
    

    Demo: http://jsfiddle.net/AMn9v/6/

    0 讨论(0)
提交回复
热议问题