08-03
28

随意切换的网页换肤程序

今天终于写完了一个 可以水平下拉菜单和垂直下拉菜单之间随意切换的网页换肤程序,它综合应用了水平下拉菜单,垂直下拉菜单,网页换肤等技巧.

这个程序需要用到三个文件,一个是h.css,用作水平下拉菜单的样式文件,另一个是v.css,用作垂直下拉菜单的样式文件,最后一个就是包含下拉菜单内容的网页文档test.html.

test.html文件内容:
<!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">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
<script>
  function startlist()
  {

      if(document.all)
      {

        var navRoot = document.getElementById("nav");
for(var i=0;i<navRoot.childNodes.length;i++)
        {
           node = navRoot.childNodes[i];

    if(node.nodeName == "LI")
           {
  
              node.onmouseover = function(){this.className = "hover";};
              node.onmouseout = function(){this.className = "";};
           }
        }
      }
  }
  window.onload = startlist;
  
  function changeSkin()
  {
var pathName = document.getElementById("cssfile").href;
        var fileName = pathName.substring(pathName.lastIndexOf("/")+1);
document.getElementById("cssfile").href = (fileName=="h.css"?"v.css":"h.css");
  }
</script>

<link rel="stylesheet" type="text/css" href="h.css" id="cssfile"/>
</head>
<body>
<ul id="nav">
<li>表单一
<ul>
  <li>java1</li>
  <li>java2</li>
  <li>java3</li>
</ul>
</li>
<li>表单二
<ul>
  <li>.net1</li>
  <li>.net2</li>
  <li>.net3</li>
</ul>
</li>
<li><a href="#" onclick="changeSkin()">切换皮肤</a></li>
</ul>
<div id="content">

</div>
</body>
</html>


h.css文件内容:
#content {clear:both;}
ul {
list-style:none;
margin:0px;
padding:0px;
     }

li{
margin:0px;
padding:0px;
  float:left;
  width:100px;
        height: 20px;
border:1px solid #ddd;
position: relative;
  }
li ul{
background-color:#eee;
display:none;
top:20px;
        left:0px;
position:absolute;
}
li:hover,li.hover {background-color:#eee;}
li:hover,li.hover ul{
   display:block;
  }


v.css文件内容:

#nav {float:left;}
ul {
list-style:none;
margin:0px;
padding:0px;
     }

li{
margin:0px;
padding:0px;
  width:100px;
        height: 20px;
border:1px solid #ddd;
position: relative;
  }
li ul{
background-color:#eee;
display:none;
top:0px;
        left:100px;
position:absolute;
}
li:hover,li.hover {background-color:#eee;}
li:hover,li.hover ul{
   display:block;
  }


文章来自: 本站原创
引用通告: 查看所有引用 | 我要引用此文章
Tags: CSS JS
相关日志:
评论: 0 | 引用: 0 | 查看次数: 517
发表评论
昵 称:
密 码: 游客发言不需要密码.
内 容:
验证码: 验证码
选 项:
虽然发表评论不用注册,但是为了保护您的发言权,建议您注册帐号.
字数限制 1000 字 | UBB代码 开启 | [img]标签 关闭