Results 1 to 3 of 3

Thread: Close div after X seconds no activity?

  1. #1
    Join Date
    Mar 2006
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Close div after X seconds no activity?

    I have a <div> that I show / hide with the standard JS snip for doing that.

    What I need is to figure out how to make it close after no mouse acitivity over the <div>.

    Possible?

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    /*<![CDATA[*/
    .tog {
      width:100px;height:100px;background-Color:red;
    }
    
    /*]]>*/
    </style>
    <script type="text/javascript">
    /*<![CDATA[*/
    function Toggle(id,ms){
     obj=document.getElementById(id);
     obj.style.display=obj.style.display!='none'?'none':'block';
     Close(id,ms);
    }
    
    function Close(id,ms){
     obj=document.getElementById(id);
     clearTimeout(obj.to);
     obj.to=setTimeout(function(obj){return function(){obj.style.display='none';}}(obj),ms||4000);
    }
    
    /*]]>*/
    </script>
    </head>
    
    <body>
    <a href="javascript:Toggle('tst');" >Toggle</a>
    <div id="tst" class="tog" onmousemove="Close('tst',2000);" ></div>
    <br />
    <a href="javascript:Toggle('tst1');" >Toggle</a>
    <div id="tst1" class="tog" onmousemove="Close('tst1',12000);"></div>
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. The Following User Says Thank You to vwphillips For This Useful Post:

    JBottero (12-03-2009)

  4. #3
    Join Date
    Mar 2006
    Posts
    41
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Fantastic, perfict. I've disected it to understand how it works, and been able to integrate it into my script. Thanks!

    What is the reason / purpose of using the /*<![CDATA[*/ ... /*]]>*/ "wrapper"?
    Last edited by JBottero; 12-03-2009 at 12:16 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •