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>
|