喜欢琢磨,给大家分享小编自己封装的仿layui的选项卡.

 <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>sub-tab组件-学习从模仿开始</title>
</head>
<style>
*{
list-style: none;
padding: 0;
margin: 0;
}
.sub-tab{ }
.sub-tab .sub-tab-title{
position: relative;
left: 0;
height: 40px;
white-space: nowrap;
font-size: 0;
border-bottom-width: 1px;
border-bottom-style: solid;
border-color: #e6e6e6;
}
.sub-tab .sub-tab-title li{
display: inline-block;
vertical-align: middle;
font-size: 14px;
transition: all .2s;
-webkit-transition: all .2s;
position: relative;
line-height: 40px;
min-width: 65px;
padding: 0 15px;
text-align: center;
cursor: pointer;
}
.sub-tab .sub-tab-title li.sub-tab-active{
color: #009688;
}
.sub-tab .sub-tab-title li.sub-tab-active:after{
position: absolute;
left: 0;
bottom: 0;
content: '';
width: 100%;
border: none;
border-radius: 0;
border-bottom: 2px solid #5FB878;
}
.sub-tab .sub-tab-content div{
display: none;
}
.sub-tab .sub-tab-content div.sub-tab-show{
display: block;
}
.layer{
width:200px;
height: 50px;
background-color: #ccc;
text-align: center;
line-height: 50px;
position: absolute;
top: 20px;
left:280px;
}
.layer .title{
color: red;
}
</style>
<body>
<div class="sub-tab">
<ul class="sub-tab-title">
<li class="sub-tab-active">用户管理</li>
<li>权限分配</li>
<li>商品管理</li>
</ul>
<div class="sub-tab-content">
<div class="sub-tab-item sub-tab-show">用户管理</div>
<div class="sub-tab-item">权限分配</div>
<div class="sub-tab-item">商品管理</div>
</div>
</div>
</body>
<script>
window.onload=function(){
var subTab=new SubTab();
subTab.subTabOn();
}
function SubTab(){
var _this=this;
this.subTab=document.querySelector('.sub-tab');
this.subTabTitle=document.querySelector('.sub-tab .sub-tab-title');
this.subLi=document.querySelectorAll('.sub-tab .sub-tab-title li');
this.subTabContent=document.querySelector('.sub-tab .sub-tab-content');
this.subTabItem=document.querySelectorAll('.sub-tab .sub-tab-item');
for(var i=0;i<this.subLi.length;i++){
this.subLi[i].index=i;
this.subLi[i].onclick=function(){
_this.fnClick(this);
};
}
}
SubTab.prototype.fnClick=function(oBth){
if(this.layer){
document.body.removeChild(this.layer);
}
for(var i=0;i<this.subLi.length;i++){
this.subLi[i].className="";
removeClass(this.subTabItem[i],'sub-tab-show');
}
oBth.className="sub-tab-active";
addClass(this.subTabItem[oBth.index],'sub-tab-show');
this.msg=oBth.innerHTML;
this.tabIndex=oBth.index;
this.create();
this.subTabOn(); }
SubTab.prototype.create=function(){
this.layer = document.createElement('div');
this.layer.className = 'layer';
this.layer.innerHTML = '<div class="title">切换到了'+this.tabIndex+': '+ this.msg +'</div>';
document.body.appendChild( this.layer );
console.log(this.layer);
};
SubTab.prototype.subTabOn=function(){
console.log(this.tabIndex);
console.log(this.msg);
} function addClass(element, className) {
if(!new RegExp("(^|\\s)" + className + "(\\s|$)").test(element.className)) element.className += ' ' + className;
}
function removeClass(element, className) {
element.className = element.className.replace(new RegExp("(^|\\s)" + className + "(?=(\\s|$))", "g"), '');
} </script>
</html>

功能还没完善,学习中,有问题的小伙伴可以留言给我,一起交流,共同进步.

最新文章

  1. Effective C++ 34 区分接口继承和实现继承
  2. 【BZOJ-4199】品酒大会 后缀数组 + 并查集合并集合
  3. nsarray排序
  4. jquery冲突
  5. 304 CORS
  6. 使用 hibernate 存取大对象数据类型(clob和blob)
  7. UVA 11249 - Game(游戏)
  8. Class撑起了OOP世界的天。Class类是OO的基本单元,OO的世界都是通过一个一个的类协作完成的,提高软件的重用性、灵活性和扩展性(转)
  9. Floodfill算法——求独立子图个数
  10. Jenkins+Jmeter持续集成笔记(四:定时任务和邮件通知)
  11. 数组之slice,splice,Concact,Reverse,Sort方法
  12. MySQL造数据脚本-亲试
  13. struct和union,enum分析
  14. eclipse debug Liunx服务器上的svn项目
  15. 17.async 函数
  16. Oracle VM VirtualBox安裝Windows 2000失败
  17. Java经典练习题_Day03
  18. poj1330lca入门题
  19. ajaxfileupload异步上传文件
  20. Codeforces Beta Round #27 (Codeforces format, Div. 2) E. Number With The Given Amount Of Divisors 反素数

热门文章

  1. sqler sql 转rest api 的工具试用
  2. kettle的资源库创建及修改密码
  3. node api 之:process - 进程
  4. php+js实现重定向跳转并post传参
  5. 深入理解ASP.NET MVC(8)
  6. 基于nginx + lua实现的反向代理动态更新
  7. linux 如何运行rpm
  8. JAVA的debug入门和多断电调试
  9. 开发人员行走Unix的随身四艺
  10. WPF Demo18 路由事件