代码相当简洁、简单易懂,就不多废话了。
直接奉上代码:
复制代码 代码如下:
*{ font-size: 14px;margin: 0px;}
a{color:#a0b3d6;text-decoration: none;}
.tabs{border:1px solid #a0b3d6;margin:100px;width:350px;}
.tabs-nav a{background:#eaf0fd; line-height:30px;padding:0px 20px 0px 20px;display:inline-block;border-right:1px solid #a0b3d6;border-bottom:1px solid #a0b3d6; float:left;}
.tabs-nav .on{background:white; border-bottom:1px solid white; position:relative;}
.tabs-content{display: block; padding:20px;border-top:1px solid #a0b3d6; margin-top:-1px;}
.tabs-content_hide{display: none;}
首页
技术
生活
作品
首页
技术
生活
作品
------demo.js---------------
复制代码 代码如下:
window.onload=function(){
tabs("tabs","mouseover");
}
function tabs(id,trigger){
var tabBtn = document.getElementById(id).getElementsByTagName("h2")[0].getElementsByTagName("a");
var tabsContent = document.getElementById(id).getElementsByTagName("p");
for(var i=0;i
if(trigger=='mouseover'){
tabBtn[i].onmouseover=function(){
clearClass();
this.className="on";
showContent(this.index);
}
}
function showContent(n){
for (var i=0; i
tabsContent[i].className = "tabs-content_hide";
}
tabsContent[n].className="tabs-content";
}
function clearClass(){
for(var i=0;i
}
}
}
}
是不是很简单就实现了选项卡的切换效果呢,小伙伴们自己美化下就可以用到自己项目中去了。



