Hide html element if no activity on the web page

Hide html element if no user activity on the web page

Hide the DIV, If there is no activity on the web page for more than 10 seconds. Then show the Hid DIV when user clicked the document. We can implement this scenario by using jquery as shown below.


var showinterval = 1;
setInterval(function(){
if(showinterval == 10){

/* if interval reaches 10 the user is inactive and then hide element/s */

$('.main-menu').fadeOut("slow");
showinterval = 1;
}
showinterval = showinterval+1;
//console.log(showinterval);
},1000);

//again show div when user clicked the document

$(document).bind('mousemove keypress', function() {
$('.main-menu').fadeIn("slow");
showinterval = 1;
});

You may also like

Leave a Reply

Your email address will not be published. Required fields are marked *