麦鸡的TAB切换功能结合了javascript和css_导航菜单
程序员文章站
2024-01-02 22:23:34
...
这类型东西网上多的是,但朋友说我的程序程序理念好(嘻…),我也写一个tab切换,厚着脸皮把它叫麦鸡的TAB切换(汗一把先.),转载也请注明麦鸡的博客,下面就开始了
做个滑动门,需要一个图片
CSS
.nav{position:relative}
.nav dt{float:left; margin:0 2px 0 0; position:relative; z-index:2}
.nav dt a{color:#555; text-decoration:none}
.nav dt a:hover{color:#000}
.nav dt a{
float:left; display:block; height:24px; line-height:26px; overflow:hidden;
background:url(/upload/20071217200212700.gif) no-repeat 0 -24px
}
.nav dt a span{
display: block; padding:0 15px 0 0; margin:0 0 0 15px;
background:url(/upload/20071217200212700.gif) no-repeat right -24px
}
.nav dt.on a{background-position:0 0}
.nav dt.on a span{background-position:right 0}
.nav dd{
background:#fff; border:solid 1px #ccc; width:400px; margin:0; padding:10px;
position:absolute; left:0; top:23px; z-index:1; visibility:hidden
}
.nav dd.on{visibility:visible}
/*-_-!*/
.nav dd a{display:block}
xhtml
javascript
var maiji_tab = function(num){//根据mun添加class,使它显示
var dtArray = document.getElementById('maiji_tab').getElementsByTagName("dt");//获取节点
var ddArray = document.getElementById('maiji_tab').getElementsByTagName("dd");
for (var i = 0; i dtArray[i].className = '';//取消class
ddArray[i].className = '';
}
dtArray[num].className = 'on';
ddArray[num].className = 'on';//增加class
}
演示地址
做个滑动门,需要一个图片
CSS
复制代码 代码如下:
.nav{position:relative}
.nav dt{float:left; margin:0 2px 0 0; position:relative; z-index:2}
.nav dt a{color:#555; text-decoration:none}
.nav dt a:hover{color:#000}
.nav dt a{
float:left; display:block; height:24px; line-height:26px; overflow:hidden;
background:url(/upload/20071217200212700.gif) no-repeat 0 -24px
}
.nav dt a span{
display: block; padding:0 15px 0 0; margin:0 0 0 15px;
background:url(/upload/20071217200212700.gif) no-repeat right -24px
}
.nav dt.on a{background-position:0 0}
.nav dt.on a span{background-position:right 0}
.nav dd{
background:#fff; border:solid 1px #ccc; width:400px; margin:0; padding:10px;
position:absolute; left:0; top:23px; z-index:1; visibility:hidden
}
.nav dd.on{visibility:visible}
/*-_-!*/
.nav dd a{display:block}
xhtml
复制代码 代码如下:
javascript
复制代码 代码如下:
var maiji_tab = function(num){//根据mun添加class,使它显示
var dtArray = document.getElementById('maiji_tab').getElementsByTagName("dt");//获取节点
var ddArray = document.getElementById('maiji_tab').getElementsByTagName("dd");
for (var i = 0; i dtArray[i].className = '';//取消class
ddArray[i].className = '';
}
dtArray[num].className = 'on';
ddArray[num].className = 'on';//增加class
}
演示地址