Hide a div after some time if no activity occurs on that div
Question by snell
I Am trying to hide a div when the user doesn’t click any button on it for 15 seconds.
I know how to hide and display the div by using element.style.display = 'none';
but I am not able to understand how to calculate the time after last activity on the div.
Answer by Starx
If you are familier with jquery, there is the plugin known as jquery timer(the link is below), which is going to enable you run certain code in regular interval of time.
Whenever a page or a div is initiated, setup a session, and keep the time in the session variable like $_SESSION['checkedtime'] = time();
Now use the jquery timer to sent a psot request to a file which checks the value and return the activity status a basic example of that page is like this
check.php
$oldtime = $_SESSION['checkedtime'];
if($oldtime<time()-15) { return 0; }
else { return 1; }
to setup a time function see the demo page