Skip to content

Commit 6d3bf8a

Browse files
committed
feat(MdRipple): add transition-group to remove ripple after transition
1 parent 38a8aae commit 6d3bf8a

File tree

1 file changed

+18
-27
lines changed

1 file changed

+18
-27
lines changed

src/components/MdRipple/MdRipple.vue

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<template>
22
<div
3-
class="md-ripple"
4-
:class="rippleClasses"
3+
:class="['md-ripple', rippleClasses]"
54
@touchstart.passive.stop="touchStartCheck"
65
@touchmove.passive.stop="touchMoveCheck"
76
@mousedown.passive.stop="startRipple">
87
<slot />
98

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>
9+
<transition-group name="md-ripple" @after-enter="clearWave" v-if="!isDisabled">
10+
<span v-for="(ripple, index) in ripples" :key="'ripple'+index" :class="['md-ripple-wave', waveClasses]" :style="ripple.waveStyles" />
11+
</transition-group>
1312
</div>
1413
</template>
1514

@@ -90,7 +89,6 @@
9089
})
9190
}
9291
})
93-
this.clearWaves()
9492
},
9593
applyStyles (position, size) {
9694
size += 'px'
@@ -101,12 +99,8 @@
10199
height: size
102100
}
103101
},
104-
clearWaves () {
105-
let timeout
106-
window.clearTimeout(timeout)
107-
timeout = window.setTimeout(() => {
108-
this.ripples = []
109-
}, 1000)
102+
clearWave () {
103+
this.ripples.pop()
110104
},
111105
getSize () {
112106
const { offsetWidth, offsetHeight } = this.$el
@@ -159,9 +153,7 @@
159153
background: currentColor;
160154
border-radius: 50%;
161155
opacity: 0;
162-
animation: ripple .8s $md-transition-stand-timing;
163-
transition-property: opacity, transform;
164-
will-change: opacity, transform;
156+
transform: scale(2) translateZ(0);
165157
166158
&.md-centered {
167159
animation-duration: 1.2s;
@@ -174,18 +166,17 @@
174166
}
175167
}
176168
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);
169+
.md-ripple-enter-active {
170+
transition: .8s $md-transition-stand-timing;
171+
transition-property: opacity, transform;
172+
will-change: opacity, transform;
173+
&.md-centered {
174+
transition-duration: 1.2s;
189175
}
190176
}
177+
178+
.md-ripple-enter {
179+
opacity: .26;
180+
transform: scale(.26) translateZ(0);
181+
}
191182
</style>

0 commit comments

Comments
 (0)