avatar

目录
css3动画之悬浮

示例

语法

  • 列表函数
    • 获取列表的长度 length(@backgroundColor) //4
    • 获取列表元素 extract(@backgroundColor, 3) //rgb(72, 197, 174)
  • 循环函数
    • loop定义循环次数,when条件判断,符合进入函数,不符合不进入函数。之后次数+1,形成循环。
    • loop函数调用,直接传值1。

题目

  1. 鼠标悬浮之后,底部颜色条动画过渡到高度100%;
  2. 使用less语法,遍历颜色。
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
144
145
146
147
148
149
150
151
152
153
154
155
<template>
<div style="padding: 20px;">
<h4 style="padding: 10px 0;">动画cssh4>
<ul class="order_box">
<li v-for=" orderItem of orderList" :key="orderItem.id" class="order_box_item">
<p class="title">{{orderItem.title}}p>
<p class="value">{{orderItem.value}}p>
<div :class="'bottom bottom_'+orderItem.id ">div>
li>
ul>
div>
template>
<script>
export default {
data() {
return {
count: 0, //计数
firstName: "Foo",
lastName: "Bar",
orderList: [
{ id: 1, value: 1, title: "待支付", color: "rgb(109, 179, 226)" },
{ id: 2, value: 4, title: "待发货", color: "rgb(250, 125, 119)" },
{ id: 3, value: 30, title: "待收货", color: "rgb(72, 197, 174)" },
{ id: 4, value: 1, title: "待评价", color: "rgb(250, 192, 84)" }
]
};
},
methods: {
increment() {
this.count++;
}
}
};
script>
<style lang="less" scoped>
//1)普通变量,不能重复定义
@themeColor: green;

//2)选择器变量
@mySelector: .bottom;

// 3)属性变量
@positionStyle: position;
@absolute: absolute;

//6) 变量运算

@width: 15px;
@color: #111;
//定义一个背景颜色的集合
@backgroundColor: rgb(109, 179, 226), rgb(250, 125, 119), rgb(72, 197, 174),
rgb(250, 192, 84);

//获取背景颜色的长度
@backgroundLen: length(@backgroundColor);
.loop(@index) when (@index < = @backgroundLen) {
.backgroundcard(@index, extract(@backgroundColor, @index));
.loop (@index+1);
}
.loop(1);

.backgroundcard(@className,@colorValue) {
//less:A
.bottom_@{className} {
background: @colorValue;
transition: all 0.3s;
}
//less:B
.order_box_item:hover .bottom_@{className} {
height: 100%;
z-index: -1;
}
}
//亲,您少些了下面很多重复的代码 css A
// .bottom_1 {
// background: rgb(109, 179, 226);
// transition: all 0.3s;
// }
// .bottom_2 {
// background: rgb(250, 125, 119);
// transition: all 0.3s;
// }
// .bottom_3 {
// background: rgb(72, 197, 174);
// transition: all 0.3s;
// }
// .bottom_4 {
// background: rgb(250, 192, 84);
// transition: all 0.3s;
// }

.order_box {
width: 1000px;
position: relative;

&_item {
//&_item 理解为order_box_item
width: calc((100% - @width * 4) / 4);
margin: 0 15px 0 0;

display: inline-block;
text-align: center;
padding: 15px 0px;
cursor: pointer;
background: #f6f6f6;
position: relative;

&:hover {
background: transparent;
.title,
.value {
color: #fff;
}
// css B
// .bottom_1 {
// height: 100%;
// z-index: -1;
// }
// .bottom_2 {
// height: 100%;
// z-index: -1;
// }
// .bottom_3 {
// height: 100%;
// z-index: -1;
// }
// .bottom_4 {
// height: 100%;
// z-index: -1;
// }
}

.title {
color: #666;
z-index: 10;
font-size: 12px;
padding: 10px 0;
}
.value {
color: @color * 3; //#333
font-weight: 500;
font-size: 26px;
z-index: 10;
}
@{mySelector} {
// position: absolute;
@{positionStyle}: @absolute; //变量名 必须使用大括号包裹
width: 100%;
height: 10px;
// background: @themeColor;
bottom: 0;
}
}
}
style>
文章作者: 会吃鱼的猫
文章链接: https://lovecatdog.github.io/2020/03/12/css3%E5%8A%A8%E7%94%BB%E4%B9%8B%E6%82%AC%E6%B5%AE/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 LoveCatDog
打赏
  • 微信
    微信
  • 支付宝
    支付宝

评论
简体中文