Home Ajax Jquery jQuery Drop Down Menu

Related Tutorials


 
 

Share on Google+Share on Google+

jQuery Drop Down Menu

Advertisement
In this JQuery tutorial we will develop a program to make Drop Down menu

jQuery Drop Down Menu

     

In this JQuery tutorial we will develop a program  to make Drop Down menu

Steps to develop the Drop Down menu .

Step 1:

 

 

 

 

Create a new file (suckerfish.html) and add the following code into it:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<title>jQuery  Drop Down Menu</title>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#van-one li").hover(
function(){ $("ul", this).fadeIn("slow"); }, 
function() { } 
);
if (document.all) {
$("#van-one li").hoverClass ("sfHover");
}
});

$.fn.hoverClass = function(c) {
return this.each(function(){
$(this).hover( 
function() { $(this).addClass(c); },
function() { $(this).removeClass(c); }
);
});
}; 
</script>

<style type="text/css">

/* vanigation */
.van, .van ul { 
list-style: none;
margin: 0;
padding: 0;
}

.van {
font-family: Arial, Helvetica, sans-serif;
z-index: 100;
position: relative;
}
.van li {
border-left: 1px solid #000;
float: left;
margin: 0;
padding: 0;
position: relative;
}
.van li a, .van li a:link, .van li a:active, .van li a:visited {
font: bold 1.22em/25px Arial, Helvetica, sans-serif;
background: #EFEFEF;
color: #ff0000;
display: block;
padding: 0 9px;
text-transform: lowercase;
text-decoration: none;
}

.van li a:hover {
background: #ccc;
color: #000; 

}
#van-one li:hover a, 
#van-one li.sfHover a {
background: #ccc;
color: #000;
}
#van-one li:hover ul a, 
#van-one li.sfHover ul a {
background: #F0ff0f;
color: #000000; 
}
#van-one li:hover ul a:hover, 
#van-one li.sfHover ul a:hover {
background: #ccc;
color: #000; 
}

.van ul {
background: #565656;
border-bottom: 1px solid #000;
list-style: none;
margin: 0;
width: 100px;
position: absolute;
top: -999em;
left: -1px;
}
.van li:hover ul,
.van li.sfHover ul {
top: 25px;
}
.van ul li {
border: 0;
float: none;
}
.van ul a {
border: 1px solid #000;
border-bottom: 0;
padding-right: 20px;
width: 80px;
white-space: nowrap;
}
.van ul a:hover {
background: #ccc;
color: #000;
}
</style>
</head>
<body>

<ul id="van-one" class="van">
<li>

<a href="#item1">item A</a>
<ul>
<li><a href="#itemA1">item A1</a></li>
<li><a href="#itemA2">item A2</a></li>
<li><a href="#itemA3">item A3</a></li>
<li><a href="#itemA4">item A4</a></li>

</ul>
</li>
<li>
<a href="#item2">item B</a>
<ul>
<li><a href="#itemB1">item B1</a></li>
<li><a href="#itemB2">item B2</a></li>

</ul>
</li>
<li>
<a href="#item3">item C</a>
<ul>
<li><a href="#itemC1">item C1</a></li>
<li><a href="#itemC2">item C2</a></li>

</ul>
</li>

</ul>

<br clear="all" />

</body>
</html>

Program explanation:

The following code includes the jQuery JavaScript library file:

<script type="text/javascript" src="jquery.js"></script>

The Code

$("#van-one li").hover

 This function works when  generate an hover event and having correponding style css.

van li a:hover {
background: #ccc;
color: #000; 

}
#van-one li:hover a, 
#van-one li.sfHover a {
background: #ccc;
color: #000;
}
#van-one li:hover ul a, 
#van-one li.sfHover ul a {
background: #F0ff0f;
color: #000000; 
}
#van-one li:hover ul a:hover, 
#van-one li.sfHover ul a:hover {
background: #ccc;
color: #000; 
}

 

 

we using  ul (unordered list) and impelement a style on it.

 

 

Check online demo of the application

Learn from experts! Attend jQuery Training classes.

Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: September 8, 2008

Related Tutorials

Discuss: jQuery Drop Down Menu   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:2
Borja
February 23, 2012
wXcXgWeCIx

I don't namorlly check out these kinds of sites (I'm a pretty modest person) but even though I was a little surprised as I was reading, I was definitely a bit titillated as well. Thanks for making my day
Allah noor burki
March 21, 2012
dropdown menu

it is a very good work. I realy appriciate it. I m the bigginer in jquery. But i under stand it very easily.
DMCA.com