tab
追随动画
hover to change
- tab1
- tab2
- tab3
- tab4
- tab5
详细代码
vue
<template>
<div class="tab-container">
<ul class="tabs">
<li class="tab-item" v-for="n in 5">tab{{ n }}</li>
</ul>
</div>
</template>
<style scoped lang="scss">
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
.tab-container {
border: 1px solid #eee;
margin: 0 auto;
.tabs {
display: flex;
justify-content: center;
align-items: center;
.tab-item {
position: relative;
height: 40px;
line-height: 40px;
padding: 0 20px;
font-size: 18px;
color: #909399;
background-color: #fff;
margin-top: 8px;
cursor: pointer;
&::after {
content: "";
width: 0;
height: 2px;
background-color: #00adb5;
position: absolute;
left: 100%;
bottom: 0;
transition: all .4s;
}
&:hover {
color: #00adb5;
&::after {
width: 100%;
left: 0;
transition-delay: 0.1s;
}
&~li::after {
left: 0;
}
}
}
}
}
</style>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
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
中间展开
click to change
- tab1
- tab2
- tab3
- tab4
- tab5
详细代码
vue
<script setup>
import { ref } from 'vue'
const isActive = ref(1)
const setActive = (index) => {
isActive.value = index
}
</script>
<template>
<div class="tab-container3">
<ul class="tabs">
<li class="tab-item" v-for="n in 5" :class="{ active: isActive == n }" @click="setActive(n)">
tab{{ n }}
</li>
</ul>
</div>
</template>
<style scoped lang="scss">
ul,
li {
margin: 0;
padding: 0;
list-style: none;
}
.tab-container3 {
border: 1px solid #eee;
margin: 0 auto;
.tabs {
display: flex;
justify-content: center;
align-items: center;
li {
height: 40px;
line-height: 40px;
padding: 0 15px;
margin-top: 8px;
cursor: pointer;
position: relative;
font-size: 18px;
color: #909399;
background-color: #fff;
&::after {
content: "";
width: 0;
height: 2px;
background-color: #00adb5;
position: absolute;
left: 0;
right: 0;
margin: auto;
bottom: 0;
transition: width .4s;
}
}
li.active {
&::after {
width: 100%;
}
}
}
}
</style>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
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