This repository has been archived by the owner on Sep 24, 2022. It is now read-only.
generated from antfu-collective/vitesse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
RedPacketDemo.vue
116 lines (103 loc) · 2.24 KB
/
RedPacketDemo.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
<div class="packet mt-2 max-w-[260px] w-250px max-h-[300px] h-40vh">
<div
ref="target"
class="opener z-0"
/>
<div class="hole-wrap">
<div class="hole"></div>
<div
ref="sparkle"
class="w-full flex justify-center "
>
<span class="text-4xl">
✨
</span>
</div>
</div>
<div class="grid place-items-center absolute z-10 inset-0 w-full h-full">
<button class="w-4rem h-4rem rounded-full cursor-pointer ring-yellow-200 ring-3 transform scale-100 focus:outline-none bg-orange-400 hover:bg-orange-300 hover:scale-105 transition-colors" @click="toggle">
{{ opened ? 'Close' : 'Open' }}
</button>
</div>
</div>
</template>
<script setup lang='ts'>
import { useMotion } from '@vueuse/motion'
const target = ref<HTMLElement>()
const sparkle = ref<HTMLElement>()
const opened = ref(false)
const motionInstance = useMotion(target, {
initial: {
rotateX: 0,
},
enter: {
rotateX: 180,
},
})
const motionInstance2 = useMotion(sparkle, {
initial: {
opacity: 0,
y: 0,
scale: 1,
},
enter: {
opacity: 1,
scale: 1.5,
y: 10,
transition: {
delay: 300,
},
},
})
const openRedPacket = () => {
motionInstance.apply('enter')
motionInstance2.apply('enter')
}
const closeRedPacket = () => {
motionInstance.apply('initial')
motionInstance2.apply('initial')
}
// close packet on initial mount
onMounted(() => closeRedPacket())
const toggle = () => {
opened.value = !opened.value
opened.value ? openRedPacket() : closeRedPacket()
}
</script>
<style scoped>
.packet {
background: red;
position: relative;
perspective: 1000px;
display: flex;
justify-content: center;
align-items: center;
}
.packet .opener {
z-index: 2;
height: 30%;
background: pink;
width: inherit;
border-radius: 0 0 50% 50%;
position: absolute;
top: 0;
transform-style: preserve-3d;
transform-origin: top;
}
.packet .hole-wrap {
width: inherit;
height: 100%;
position: relative;
overflow: hidden;
}
.packet .hole-wrap .hole {
height: 20%;
background: rgb(231, 20, 20);
width: inherit;
border-radius: 0 0 50% 50%;
position: absolute;
transform: translateY(-50%);
top: 0;
}
</style>