-
Notifications
You must be signed in to change notification settings - Fork 0
/
8_tabs_transition.html
58 lines (58 loc) · 1.38 KB
/
8_tabs_transition.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<style>
.nav{position:relative}
.tabs{list-style:none; padding:0}
.tabs a{
text-decoration:none;
color:#000;
width:100px; height:40px;
line-height:40px; text-align:center;
display:inline-block;
}
.tabs>li{
float:left;
border-bottom:1px solid #000;
}
.box{
width:100px; height:39px;
border:1px solid #000;
border-bottom:1px solid #fff;
position:absolute; top:0; left:0;
transition:all .5s linear;
}
</style>
</head>
<body>
<h1>使用属性选择器实现标签页头的切换</h1>
<div class="nav">
<ul class="tabs">
<li><a href="#">十元套餐</a></li>
<li><a href="#">二十元套餐</a></li>
<li><a href="#">三十元套餐</a></li>
</ul>
<div class="box"></div>
</div>
<script src="js/jquery-1.11.3.js"></script>
<script>
// $("ul.tabs a").click(function(){
// var $a=$(this);
// var i=$("ul.tabs a").index($a);
// //.indexOf
// //$a.parent().prevAll().length;
// $(".box").css("left",i*100)
// })
$("ul.tabs>li>a").click(function(e){
e.preventDefault()
// var $a=$(this)
// var $div=$("div.box")
// var i=$a.parent().index()
// $div.css("left",100*i)
var i=$("ul.tabs>li>a").index(this)
$("div.box").css("left",100*o)
})
</script>
</body>
</html>