www.webdeveloper.com
Results 1 to 2 of 2

Thread: Timers in javascipt

  1. #1
    Join Date
    Jun 2009
    Posts
    1

    Timers in javascipt

    Hi All,

    I have created a javascript that uses the onmouseover command to display certain text of a left navigational menu. The problem is that i need for the text to be displayed 1 or 2 seconds after the onmouseover command is triggered. I have tried to use different versions of timers but have been unable to get this to work.

    Does anyone know how to put a timer on a onmouseover command? Any assistance would be most appreciated.

  2. #2
    Join Date
    Apr 2007
    Posts
    1,664
    Here you go. This shows a div and writes content to it. I'm sure you can make it fit your needs. vwphillips helped me with this just last week.

    HTML Code:
    <html>
    <head>
    <script language="JavaScript">
    <!--
    var myTimer;
    var x;
    var y;
     
    function get_xy(event){
    	x = event.clientX;
    	y = event.clientY;
    }
     
    function viewMe(id){
            var myId=document.getElementById(id);
            hide(id);
            //capture the  mouse
            myId.style.position = "absolute";
            myId.style.top = y + 10 +"px";
            myId.style.left = x + 10 +"px";
            show(id);
            myId.innerHTML="Write me in that div";
            
    }
    function show(id){
            document.getElementById(id).style.display="block";
    }
     
    function hide(id){
            document.getElementById(id).style.display="none";
    }
     
    </script>
    </head>
    <body>
    
    <a href="javascript:void(0);" 
    onmouseover="get_xy(event);myTimer=setTimeout(&quot;viewMe('myDiv')&quot;,1000);" 
    onmouseout="clearTimeout(myTimer);hide('myDiv')">test</a>
     
    <div id="myDiv" style="border:1px solid black;display:none;"></div>
     
    </body>
    </html>
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles