forked from zhangmengxue/Fragment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtab.html
143 lines (138 loc) · 4 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
137
138
139
140
141
142
143
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8>
<title>Tab切换 demo</title>
<style type="text/css">
*{
margin:0;
padding:0;
font-size: 12px;
list-style: none;
}
.notice{
width:352px;
height:168px;
margin:10px;
border: 5px #ef4c6c solid;
overflow:hidden;
}
.notice-tit{
height:52px;
position:relative;
background:#f7f7f7;
}
.notice-tit li a{
display:inline-block;
float:left;
padding:14px;
width:42px;
font-size: 1.5em;
text-decoration: none;
border-bottom: 1px #ef4c6c solid;
}
.notice-tit li.select a{
background-color:#fff;
border-left: 1px #ef4c6c solid;
border-right: 1px #ef4c6c solid;
border-bottom: 3px #fff solid;
}
.notice-tit li a:hover{
color:#f90;
}
.mod a{
display:inline-block;
float:left;
margin:10px;
width:150px;
height:35px;
text-decoration: none;
}
</style>
</head>
<body>
<div id="notice" class="notice">
<div id="notice-tit" class="notice-tit">
<ul>
<li><a href="#">公告</a></li>
<li><a href="#">规则</a></li>
<li><a href="#">论坛</a></li>
<li><a href="#">安全</a></li>
<li class="select"><a href="#">公益</a></li>
</ul>
</div>
<div id="notice-con" class="notice-con">
<div class="mod" style="display:none">
<ul>
<li><a href="#">我是公告内容</a></li>
<li><a href="#">我是公告内容</a></li>
<li><a href="#">我是公告内容</a></li>
<li><a href="#">我是公告内容</a></li>
</ul>
</div>
<div class="mod" style="display:none">
<ul>
<li><a href="#">内容规则</a></li>
<li><a href="#">内容规则</a></li>
<li><a href="#">内容规则</a></li>
<li><a href="#">内容规则</a></li>
</ul>
</div>
<div class="mod" style="display:none">
<ul>
<li><a href="#">论坛</a></li>
<li><a href="#">论坛</a></li>
<li><a href="#">论坛</a></li>
<li><a href="#">论坛</a></li>
</ul>
</div>
<div class="mod" style="display:none">
<ul>
<li><a href="#">content4</a></li>
<li><a href="#">content4</a></li>
<li><a href="#">content4</a></li>
<li><a href="#">content4</a></li>
</ul>
</div>
<div class="mod" style="display:block">
<ul>
<li><a href="#">content5</a></li>
<li><a href="#">content5</a></li>
<li><a href="#">content5</a></li>
<li><a href="#">content5</a></li>
</ul>
</div>
</div>
</div>
<script type="text/javascript">
window.onload = function(){
var titles = document.getElementById('notice-tit').getElementsByTagName('li');
var divs =document.getElementById('notice-con').getElementsByTagName('div');
var index = 0;
var timer = null;
if(titles.length!=divs.length){return;}
for(var i=0;i<titles.length;i++){
console.log(0);
titles[i].id = i;
titles[i].onmouseover = function(e){
if(timer){
clearTimeout(timer);
timer = null;
}
var that = this;
timer = setTimeout(function(){
//清除所有li上的class
for(var j=0;j<titles.length;j++){
titles[j].className='';
divs[j].style.display = 'none';
}
//设置当前高亮显示
that.className = 'select';
divs[that.id].style.display = 'block';
},500);
}
}
}
</script>
</body>
</html>