/
Tab组件.html
136 lines (114 loc) · 3.12 KB
/
Tab组件.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
* {
box-sizing: border-box;
}
.clearfix:after {
content: "";
display: block;
clear: both;
}
ul,
li {
list-style: none;
margin: 0;
padding: 0;
}
.tab {
width: 600px;
border: 1px solid #ccc;
margin: 50px auto;
}
.tab-header li {
float: left;
/*width: 33.33%;*/
padding: 10px 20px;
border: 1px solid #ccc;
border-radius: 5px;
cursor: pointer;
}
.tab-header .active {
background: #ccc;
}
.tab-content {
background: #eee;
padding: 10px;
height: 200px;
}
.tab-content li {
display: none;
}
.tab-content li.see {
display: block;
}
</style>
</head>
<body>
<section class="tab">
<ul class="tab-header clearfix">
<li class="active">tab1</li>
<li>tab2</li>
<li>tab3</li>
</ul>
<ul class="tab-content">
<li class="see">内容1</li>
<li>内容2</li>
<li>内容3</li>
</ul>
</section>
<section class="tab">
<ul class="tab-header clearfix">
<li class="active">tab1</li>
<li>tab2</li>
<li>tab3</li>
<li>tab4</li>
<li>tab5</li>
</ul>
<ul class="tab-content">
<li class="see">内容1</li>
<li>内容2</li>
<li>内容3</li>
<li>内容4</li>
<li>内容5</li>
</ul>
</section>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script>
Tab = function(){
function _Tab($target){
this.$target = $target
this.init()
this.bind()
}
_Tab.prototype.init = function(){
this.header = this.$target.find("ul").eq(0)
this.content = this.$target.find("ul").eq(1)
}
_Tab.prototype.bind = function(){
var _this = this
_this.header.on("click", "li", function(){
var index = $(this).index()
_this.header.find("li").removeClass("active")
$(this).addClass("active")
_this.content.find("li").removeClass("see")
_this.content.find("li").eq(index).addClass("see")
})
}
return {
init: function($node){
$node.each(function(){
new _Tab($(this))
})
}
}
}()
Tab.init($(".tab"))
</script>
</body>
</html>