08-03
28
随意切换的网页换肤程序
作者:Java伴侣 日期:2008-03-28
今天终于写完了一个 可以水平下拉菜单和垂直下拉菜单之间随意切换的网页换肤程序,它综合应用了水平下拉菜单,垂直下拉菜单,网页换肤等技巧.
这个程序需要用到三个文件,一个是h.css,用作水平下拉菜单的样式文件,另一个是v.css,用作垂直下拉菜单的样式文件,最后一个就是包含下拉菜单内容的网页文档test.html.
test.html文件内容:
h.css文件内容:
v.css文件内容:
这个程序需要用到三个文件,一个是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>
"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;
}
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;
}
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;
}
评论: 0 | 引用: 0 | 查看次数: 570
发表评论