Skip to content

Commit 38a8aae

Browse files
committed
feat(MdRipple): multiple waves
1 parent 6a719b5 commit 38a8aae

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

src/components/MdRipple/MdRipple.vue

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
@mousedown.passive.stop="startRipple">
88
<slot />
99

10-
<transition name="md-ripple" @after-enter="clearWave" v-if="!isDisabled">
11-
<span class="md-ripple-wave" :class="waveClasses" :style="waveStyles" v-if="animating" ref="rippleWave" />
12-
</transition>
10+
<template v-if="!isDisabled">
11+
<span v-for="(ripple, index) in ripples" :key="'ripple'+index" class="md-ripple-wave" :class="waveClasses" :style="ripple.waveStyles" />
12+
</template>
1313
</div>
1414
</template>
1515

@@ -25,10 +25,9 @@
2525
mdCentered: Boolean
2626
},
2727
data: () => ({
28-
eventType: null,
29-
waveStyles: null,
30-
animating: false,
31-
touchTimeout: null
28+
ripples: [],
29+
touchTimeout: null,
30+
eventType: null
3231
}),
3332
computed: {
3433
isDisabled () {
@@ -84,28 +83,30 @@
8483
position = this.getHitPosition($event, size)
8584
}
8685
87-
await this.clearWave()
88-
8986
this.eventType = $event.type
90-
this.animating = true
91-
this.applyStyles(position, size)
87+
this.ripples.push({
88+
animating: true,
89+
waveStyles: this.applyStyles(position, size)
90+
})
9291
}
9392
})
93+
this.clearWaves()
9494
},
9595
applyStyles (position, size) {
9696
size += 'px'
9797
98-
this.waveStyles = {
98+
return {
9999
...position,
100100
width: size,
101101
height: size
102102
}
103103
},
104-
clearWave () {
105-
this.waveStyles = null
106-
this.animating = false
107-
108-
return this.$nextTick()
104+
clearWaves () {
105+
let timeout
106+
window.clearTimeout(timeout)
107+
timeout = window.setTimeout(() => {
108+
this.ripples = []
109+
}, 1000)
109110
},
110111
getSize () {
111112
const { offsetWidth, offsetHeight } = this.$el
@@ -158,31 +159,33 @@
158159
background: currentColor;
159160
border-radius: 50%;
160161
opacity: 0;
161-
transform: scale(2) translateZ(0);
162+
animation: ripple .8s $md-transition-stand-timing;
163+
transition-property: opacity, transform;
164+
will-change: opacity, transform;
162165
163166
&.md-centered {
167+
animation-duration: 1.2s;
164168
top: 50%;
165169
left: 50%;
166170
}
167-
168-
~ * {
171+
~ *:not(.md-ripple-wave) {
169172
position: relative;
170173
z-index: 2;
171174
}
172175
}
173176
174-
.md-ripple-enter-active {
175-
transition: .8s $md-transition-stand-timing;
176-
transition-property: opacity, transform;
177-
will-change: opacity, transform;
178-
179-
&.md-centered {
180-
transition-duration: 1.2s;
177+
@keyframes ripple {
178+
0% {
179+
opacity: 0;
180+
transform: scale(0) translateZ(0);
181+
}
182+
20% {
183+
opacity: .26;
184+
transform: scale(.26) translateZ(0);
185+
}
186+
100% {
187+
opacity: 0;
188+
transform: scale(2) translateZ(0);
181189
}
182-
}
183-
184-
.md-ripple-enter {
185-
opacity: .26;
186-
transform: scale(.26) translateZ(0);
187190
}
188191
</style>

0 commit comments

Comments
 (0)