js+css实现导航效果实例

时间:2021-05-26

本文实例讲述了js+css实现导航效果的方法。分享给大家供大家参考。具体实现方法如下:

1. 程序代码如下:

复制代码 代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://mand("BackgroundImageCache", false, true);</script><!-- IE6背景图片闪烁问题 -->
</head>
<body>
<div class="menu">
<div id="menu1" class="menusel">
<h2><a href="/">菜单1</a></h2>
<div class="position">
<ul class="clearfix typeul">
<li><a href="https://www.jb51.net">菜单选项1-2</a></li>
<li>
<a href="#">菜单选项1-2</a>
<ul>
<li class="fli"><a href="#">菜单选项1-2-1</a></li>
<li class="lli"><a href="#">菜单选项1-2-2</a></li>
</ul>
</li>
<li><a href="https://www.jb51.net">菜单选项1-2</a></li>
<li class="lli"><a href="#">菜单选项1-2</a></li>
</ul>
</div><!-- position -->
</div><!-- menusel -->
<div id="menu2" class="menusel">
<h2><a href="#">菜单2</a></h2>
<div class="position">
<ul class="clearfix typeul">
<li><a href="#">菜单选项2-2</a></li>
<li><a href="#">菜单选项2-2</a>
<ul>
<li class="fli"><a href="#">菜单选项2-2-1</a></li>
<li class="lli"><a href="#">菜单选项2-2-2</a>
<ul>
<li class="fli"><a href="#">菜单选项2-2-1</a></li>
<li class="lli"><a href="#">菜单选项2-2-2</a>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#">菜单选项2-2</a></li>
<li class="lli"><a href="#">菜单选项2-2</a></li>
</ul>
</div><!-- position -->
</div><!-- menusel -->
<div id="menu3" class="menusel">
<h2><a href="#">菜单3</a></h2>
<div class="position">
<ul class="clearfix typeul">
<li><a href="#">菜单选项3-2</a></li>
<li><a href="#">菜单选项3-2</a>
<ul>
<li class="fli"><a href="#">菜单选项3-2-1</a></li>
<li class="lli"><a href="#">菜单选项3-2-2</a>
<ul>
<li class="fli"><a href="#">菜单选项3-2-1</a></li>
<li class="lli"><a href="#">菜单选项3-2-2</a>
<ul>
<li class="fli"><a href="#">菜单选项3-2-1</a></li>
<li class="lli"><a href="#">菜单选项3-2-2</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li><a href="#">菜单选项3-2</a></li>
<li class="lli"><a href="#">菜单选项3-2</a></li>
</ul>
</div><!-- position -->
</div><!-- menusel -->
</div><!-- menu -->
<script type="text/javascript">
for(var x = 1; x < 4; x++)
{
var menuid = document.getElementById("menu"+x);
menuid.num = x;
type();
}
function type()
{
var menuh2 = menuid.getElementsByTagName("h2");
var menuul = menuid.getElementsByTagName("ul");
var menuli = menuul[0].getElementsByTagName("li");
menuh2[0].onmouseover = show;
menuh2[0].onmouseout = unshow;
menuul[0].onmouseover = show;
menuul[0].onmouseout = unshow;
function show()
{
menuul[0].className = "clearfix typeul block"
}
function unshow()
{
menuul[0].className = "typeul"
}
for(var i = 0; i < menuli.length; i++)
{
menuli[i].num = i;
var liul = menuli[i].getElementsByTagName("ul")[0];
if(liul)
{
typeshow()
}
}
function typeshow()
{
menuli[i].onmouseover = showul;
menuli[i].onmouseout = unshowul;
}
function showul()
{
menuli[this.num].getElementsByTagName("ul")[0].className = "block";
}
function unshowul()
{
menuli[this.num].getElementsByTagName("ul")[0].className = "";
}
}
</script>
</body>
</html>

2. 程序效果

希望本文所述对大家的javascript程序设计有所帮助。

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章