开发者

Hide a div after some time if no activity occurs on that div

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 activ开发者_如何学Goity on the div.


  • Put a timer that will hide a div after 15 seconds
  • For each click, reset the timer to 15 seconds.


This clearTimeOut example might help to get you started. The instructions provided by Konerak provide the logic. :)


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

http://www.evanbyrne.com/article/jquery-timer-plugin

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜