/
index.vue
98 lines (90 loc) · 1.9 KB
/
index.vue
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
<template>
<div class="food-picker">
<transition name="roll">
<div v-show="foodInfo.count" class="reduce-wrapper" @click="reduce">
<i class="iconfont reduce"></i>
</div>
</transition>
<transition name="fade">
<div class="counter" v-show="foodInfo.count">{{ foodInfo.count }}</div>
</transition>
<div ref="addWrapper" class="add-wrapper" @click="add">
<i class="iconfont add"></i>
</div>
</div>
</template>
<script>
import createBall from "@/components/ball/main.js";
export default {
name: "food-picker",
props: {
foodInfo: {
type: Object,
default: () => ({}),
},
},
methods: {
reduce() {
if (parseInt(this.foodInfo.count) > 0) {
this.foodInfo.count--;
}
},
add() {
this.foodInfo.count++;
const pos = this.$refs.addWrapper.getBoundingClientRect();
const cartIconEl = document.getElementById("cartIcon");
const cartIconPos = cartIconEl.getBoundingClientRect();
const $ball = createBall({
startX: pos.left,
startY: pos.top,
endX: cartIconPos.left,
endY: cartIconPos.top,
duration: "500ms",
});
},
},
};
</script>
<style lang="less" scoped>
@duration: .6s;
.roll-enter-active,
.roll-leave-active {
transition: transform @duration;
}
.roll-enter,
.roll-leave-to {
transform: translateX(300%) rotate(calc(360deg * 1));
}
.fade-enter-active,
.fade-leave-active {
transition: opacity @duration;
}
.fade-enter,
.fade-leave-to {
opacity: 0;
}
.food-picker {
max-width: 300px;
display: flex;
align-items: center;
.add-wrapper {
position: relative;
}
.add-wrapper,
.reduce-wrapper {
display: flex;
align-items: center;
justify-content: center;
width: 50px;
height: 50px;
}
.iconfont {
color: #00a0dc;
font-size: 50px;
}
.counter {
width: 100px;
text-align: center;
}
}
</style>