麦鸡的TAB切换功能结合了javascript和css

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

麦鸡的TAB切换功能结合了javascript和css

  2020-05-12 我要评论
这类型东西网上多的是,但朋友说我的程序程序理念好(嘻…),我也写一个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

复制代码 代码如下:

<dl class="nav" id="maiji_tab"> 

<dt class="on"> 
  <a href="#this" href="#this" onclick="maiji_tab(0)"><span>精品文章</span></a> 
<https://img.qb5200.com/download-x/dt> 
<dt> 
  <a href="#this" href="#this" onclick="maiji_tab(1)"><span>视频</span></a> 
<https://img.qb5200.com/download-x/dt> 
<dt> 
  <a href="#this" href="#this" onclick="maiji_tab(2)"><span>照片</span></a> 
<https://img.qb5200.com/download-x/dt><dt> 
  <a href=”http://www.wler.cn/blog” href=”http://www.wler.cn/blog” target=”_blank”><span>麦鸡的博客</span></a> 
<https://img.qb5200.com/download-x/dt> 

<dd class=”on”> 
  <p>精品文章啊!<a href=”http://www.wler.cn/blog” href=”http://www.wler.cn/blog” target=”_blank”>麦鸡的博客欢迎你!</a></p> 
<https://img.qb5200.com/download-x/dd><dd> 
  <p>视频啊!<a href=”http://www.wler.cn/blog” href=”http://www.wler.cn/blog” target=”_blank”>麦鸡的博客欢迎你!</a></p> 
<https://img.qb5200.com/download-x/dd><dd> 
  <p>你的照片呢?<a href=”http://www.wler.cn/blog” href=”http://www.wler.cn/blog” target=”_blank”>麦鸡的博客欢迎你!</a></p> 
<https://img.qb5200.com/download-x/dd><https://img.qb5200.com/download-x/dl> 

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 < ddArray.length; i++){ 
    dtArray[i].className = '';//取消class 
    ddArray[i].className = ''; 

    dtArray[num].className = 'on'; 
    ddArray[num].className = 'on';//增加class 
}

演示地址

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们