www.webdeveloper.com
Results 1 to 4 of 4

Thread: drop down menu using javascript

Hybrid View

  1. #1
    Join Date
    Nov 2013
    Posts
    44

    drop down menu using javascript

    hi!
    i am trying to creat a drop down menu using js.i have made the menu using onMouseOver event handler.but as soon as i remove the mouse it disappears.what i am trying to say is i cant hold the menu bar on the screen.i only made it for the first list item.
    please help me on this!!
    my codes are---
    Code:
    <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <style>
    *{margin:0px;padding:0px;}
    #design{
    	width:100%;
    	height:60px;
    	background-color:#00CCFF;
    }
    #design ul {
    	list-style-type:none;
    }
    #design ul li{
    	display:inline-block;
    	margin-left:10px;
    	padding:0px;
    	height:58px;
    	border:0px solid black;
    	
    }
    #design ul li a{
    	text-decoration:none;
    	font-size:30px;
    	border:0px solid black;
    
    	padding:10px;
    	margin-top:0px;
    }
    #clear{
    	background-color:#33FF33;
    	height:110px;
    	width:120px;
    	position:relative;
    	top:-150px;
    }
    #clear ul{
    	list-style-type:none;
    }
    #clear ul li{
    	margin-top:0px;
    	margin-left:5px;
    }
    #clear ul li a {
    	text-decoration:none;
    	font-size:20px;
    }
    #container{
    	width:300px;
    	height:110px;
    	overflow:hidden;
    	border:0px solid;
    }
    </style>
    <script>
    function show(elem){
    
    var drop=document.getElementById(elem);
    drop.style.webkitTransition="top .5s ease-in-out";	
    drop.style.top="0px";
    
    }
    function vanish(elem){
    	var drop=document.getElementById(elem);
    drop.style.webkitTransition="top .5s ease-in-out";	
    drop.style.top="-150px";
    	
    }
    </script>
    </head>
    
    <body>
    <div id="design">
    <ul>
    <li onMouseOver="show('clear');" onMouseOut="vanish('clear');" ><a href="d">home</a></li>
    <li><a href="d">contact us</a></li>
    <li><a href="d">aboutus </a></li>
    <li><a href="g">faqs</a></li>
    </ul>
    </div>
    <div id="container">
    <div  id="clear">
    <ul>
    <li><a href="d">my home</a></li>
    <li><a href="g">yours</a></li>
    <li><a href="r">theirs</a></li>
    <li><a href="e">hers</a></li>
    </ul>
    </div>
    </div>
    </body>
    </html>

  2. #2
    Join Date
    Nov 2013
    Location
    New York City Metro
    Posts
    1
    Here are some JavaScript changes that might help you. I used JavaScript's native setTimeout and clearTimeout functions to set a process which will be delayed by a specified number of milliseconds. When we call vanish, this delayed process (which is held within the global vanishTimeout variable) will be cleared. Within vanish, if reset equals true (reset = true unless otherwise specified), we will create a new delayed process which will hide the menu when executed. This will give the user 500 milliseconds to hover over #clear, preventing it from hiding.

    JavaScript:
    Code:
    var vanishTimeout;
    var milliseconds = 500;
    
    function show(elem){
    	var drop=document.getElementById(elem);
    	drop.style.webkitTransition="top .5s ease-in-out";	
    	drop.style.top="0px";
    }
    
    function vanish(elem, reset){
    	if(typeof reset != 'boolean'){
    		reset = true;
    	}
    	clearTimeout(vanishTimeout);
    	if(reset){
    		vanishTimeout = setTimeout(function(){
    			var drop = document.getElementById(elem);
    			drop.style.webkitTransition="top .5s ease-in-out";	
    			drop.style.top="-150px";
    		}, milliseconds);
    	}
    }
    DOM
    Code:
    <div id="clear" onMouseOver="vanish('clear', false);" onMouseOut="vanish('clear');">

  3. #3
    Join Date
    Nov 2013
    Posts
    44
    thanks!
    i have few questions on your code
    what is the function of this.and what reset not equal to boolean means.and what (reset=true) have to do with your code.can you describe their functions.
    if(typeof reset != 'boolean'){
    reset = true;
    }
    and in here
    onMouseOut="vanish('clear');">
    why you sending without a boolean value???

  4. #4
    Join Date
    Nov 2013
    Location
    Bangladesh
    Posts
    1
    The information is excellent and really helpful.
    http://www. marnetllc.com]IT Network Support[/url]

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