How to display element by mouse inactivity? [duplicate]

1

For example, the user enters the page and, while not moving the mouse after a certain time, an element appears.

    
asked by anonymous 20.04.2016 / 18:40

2 answers

1

Look at this example:

    $(function() {
    timeout = setTimeout(function() {
        window.location.href = "http://pt.stackoverflow.com";
    }, 120000);
});

$(document).on('mousemove', function() {
    if (timeout !== null) { 
        clearTimeout(timeout);
    }
    timeout = setTimeout(function() {
        window.location.href = "http://pt.stackoverflow.com";
    }, 120000);
    });

In this code, it checks the mouse movement, if in two minutes the mouse is not moved it directs to another page using window.location.href .

So you just have to change the code by removing window.location.href and adding the action that shows your DIV.

Source: Perform action after 2 minutes without moving the mouse

    
20.04.2016 / 18:52
0

<script type="text/javascript">

function carregar_tempo() {
document.getElementById('box').style.display='block';
}

</script>

<body onload="setTimeout('carregar_tempo()', 1000)">

<div id="box" style="display:none;">conteúdo</div>

1000 equals 1 second, just change.

    
20.04.2016 / 18:45