Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript timeout mouseover

    I am a Javascript novice so please bear with me here. I made a multi level menu at http://x7.ro/proiect/produse.html -first left menu item:Raticide- by using Javascript and css. What this should do is show the sub-menu on mouseover and hide it on mouseout WITH a custom delay so people have a chance to click menu items. This seems to work except for the all needed delay. I was trying to use javascript setTimeout function but I cannot seem to make it work. Think this should be easy for a pro and Id remain indebted if any of you could help. Thanks a lot.

    Below is the working code:JS and Html.
    Code:
    <SCRIPT type=text/javascript>
    function showElement(layer){
    	var myLayer = document.getElementById(layer);
    	if(myLayer.style.display=="none"){
    		myLayer.style.display="block";
    		myLayer.backgroundPosition="top";
    	} else { 
    		myLayer.style.display="none";
    	}
    }
    function hideElement(layer){
    	var myLayer = document.getElementById(layer);
    	if(myLayer.style.display=="block"){
    		myLayer.style.display="none";
    		myLayer.backgroundPosition="top";
    	} else { 
    		myLayer.style.display="block";
    	}
    }
    </SCRIPT>
    Code:
     <A class=button onMouseOver="javascript:showElement('v-menu');return false;" onMouseOut="javascript:hideElement('v-menu');return false;"  href="#"><SPAN>Raticide</SPAN></A> 
          <UL style="DISPLAY: none" id=v-menu class=v-menu>
            <LI><A href="aaa.html">PRODIORAT</A></LI>
            <LI><A href="aaa.html">	PROBRODIRAT</A></LI></UL>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,298
    Thanks
    203
    Thanked 2,561 Times in 2,539 Posts
    Code:
    <A class=button onMouseOver="setTimeout(\"showElement('v-menu')\",5000); return false"; onMouseOut="setTimeout(\"hideElement('v-menu')\", 5000); return false";  href="#"><SPAN>Raticide</SPAN></A>
    5000 = 5000 milliseconds = 5 seconds.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It doesnt do it for me. The 'Raticide' remains frozen with that code (does nothing on either mouse event). Thanks tho.


  •  

    Posting Permissions

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