Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 move. What is the best way to perform that, by using css and jQuery? Thank you in advance.

like image 303
Maay Avatar asked Nov 29 '10 16:11

Maay


1 Answers

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/

like image 180
karim79 Avatar answered Oct 04 '22 03:10

karim79