Posted by: prajapatinilesh | September 14, 2007

UL & LI Javascript + Css Menu

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml&#8221; xml:lang=”en” lang=”en”><head><title>Vertical expanding menu in CSS</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script type=”text/javascript”>
<!–
var timerVal;
window.onload=montre;
function montre(id) {
clearTimeout(timerVal);
var d = document.getElementById(id);
for (var i = 1; i<=10; i++) {
if (document.getElementById(‘smenu’+i)) {document.getElementById(‘smenu’+i).style.display=’none’;}
}
if (d) {
clearTimeout(5);
d.style.display=’block’;
}
}
function montre1(id,itemType) {
var d = document.getElementById(id);
/*for (var i = 1; i<=10; i++) {
if (document.getElementById(‘smenu’+i)) {document.getElementById(‘smenu’+i).style.display=’none’;}
}*/
if (d) {
if (itemType == ‘mainItem’) {
if (d.style.display == ‘block’) { timerVal = aFunction(id); }
}
else { d.style.display=’none’; }
}
}
function aFunction(aVariable){
//window.setTimeout(getOnTimeOut(aVariable), 500);
timerVal = setTimeout(getOnTimeOut(aVariable), 500);
//alert(timerVal);
return timerVal;
}
function getOnTimeOut(id){
return function(){ // no params
//alert(id);
var d = document.getElementById(id);
if (d) {
d.style.display=’none’;
}
}
}
//–>
</script>
<style type=”text/css”>
/* CSS issu des tutoriels http://www.alsacreations.com/articles */
/*body {
margin: 0;
padding: 0;
background: white;
font: 80% verdana, arial, sans-serif;
}
dl, dt, dd, ul, li {
margin: 0;
padding: 0;
list-style-type: none; }
#menu {
position: absolute;
top: 0;
left: 0;
}
dl#menu {
width: 15em;
}
dl#menu dt {
cursor: pointer;
margin: 2px 0;;
height: 20px;
line-height: 20px;
text-align: center;
font-weight: bold;
border: 1px solid gray;
background: #ccc;
}
dl#menu dd {
border: 1px solid gray;
}
dl#menu li {
text-align: center;
background: #fff;
}
dl#menu li a, dl#menu dt a {
color: #000;
text-decoration: none;
display: block;
border: 0 none;
height: 100%;
}
dl#menu li a:hover, dl#menu dt a:hover {
background: #eee;
}
#mentions {
font-family: verdana, arial, sans-serif;
position: absolute;
bottom : 200px;
left : 10px;
color: #000;
background-color: #ddd;
}
#mentions a {text-decoration: none;
color: #222;
}
#mentions a:hover{text-decoration: underline;
}*/
/* **************** for side menu ********************* */
body {
/*background: white;
padding:0;
margin:0;
font-family: verdana, arial, sans-serif;
font-size: 90%;
color: black;*/
margin: 0;
padding: 0;
background: white;
font: 80% verdana, arial, sans-serif;
}
dl, dt, dd, ul, li {
margin: 0;
padding: 0;
list-style-type: none;
}
#menu {
position: absolute;
/*top: 1em;
left: 1em;
width: 10em;*/
top: 0;
left: 0;
width: 10em; /* needed */
}
#menu dt {
/*cursor: pointer;
background: #A9BFCB;
height: 20px;
line-height: 20px;
margin: 2px 0;
border: 1px solid gray;
text-align: center;
font-weight: bold;*/
cursor: pointer;
margin: 2px 0;;
height: 20px;
line-height: 20px;
text-align: center;
font-weight: bold;
border: 1px solid gray;
background: #ccc;
}
#menu dd {
position: absolute;
/*z-index: 100;*/
/*left: 8em;*/
left: 10em; /* needed */
margin-top: -1.4em;
width: 10em;
/*background: #A9BFCB;*/
border: 1px solid gray;
}
#menu ul {
padding: 2px;
}
#menu li {
text-align: center;
font-size: 85%;
height: 18px;
line-height: 18px;
}
#menu li a, #menu dt a {
color: #000;
text-decoration: none;
display: block;
}
#menu li a:hover {
text-decoration: underline;
}

#mentions {
font-family: verdana, arial, sans-serif;
position: absolute;
bottom : 200px;
left : 10px;
color: #000;
background-color: #ddd;
}
#mentions a {text-decoration: none;  color: #222; }
#mentions a:hover{text-decoration: underline; }</style></head>

<body> <dl id=”menu”> <dt onmouseover=”javascript:montre();”><a href=”#”>Menu 1</a></dt> <dt onmouseover=”javascript:montre(‘smenu2’);” onmouseout=”javascript:montre1(‘smenu2′,’mainItem’);” >Menu 2</dt>
<dd style=”display: none;” id=”smenu2″ onmouseover=”javascript:montre(‘smenu2’);” onmouseout=”javascript:montre1(‘smenu2′,’subItem’);”>
<ul>
<li><a href=”#”>Sous-Menu 2.1</a></li>
<li><a href=”#”>Sous-Menu 2.2</a></li>
<li><a href=”#”>Sous-Menu 2.3</a></li>
</ul>
</dd> <dt onclick=”javascript:montre(‘smenu3’);”>Menu 3</dt>
<dd style=”display: none;” id=”smenu3″>
<ul>
<li><a href=”#”>Sous-Menu 3.1</a></li>
<li><a href=”#”>Sous-Menu 3.1</a></li>
<li><a href=”#”>Sous-Menu 3.1</a></li>
<li><a href=”#”>Sous-Menu 3.1</a></li>
<li><a href=”#”>Sous-Menu 3.1</a></li>
<li><a href=”#”>Sous-Menu 3.1</a></li>
</ul> </dd> </dl>

Reference Site Name  : :    <div id=”mentions”>Raphael GOETTER<br>
<a href=”http://www.alsacreations.com/”>Alsacréations</a><br&gt;
<a href=”http://tutorials.alsacreations.com/deroulant”>Explanations</a></div></body&gt;
</html>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: