[Improvement] uniform fade animation (#410)

This commit is contained in:
neverland 2017-12-11 20:00:26 +08:00 committed by GitHub
parent 49ef814d1e
commit 7dbb5db256
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 25 deletions

View File

@ -1,11 +1,14 @@
<template> <template>
<div <transition name="van-fade">
class="van-modal" <div
:class="className" v-show="visible"
:style="style" class="van-modal"
@touchmove.prevent.stop :class="className"
@click="$emit('click', $event)" :style="style"
/> @touchmove.prevent.stop
@click="$emit('click', $event)"
/>
</transition>
</template> </template>
<script> <script>
@ -13,6 +16,7 @@ export default {
name: 'van-modal', name: 'van-modal',
props: { props: {
visible: Boolean,
zIndex: Number, zIndex: Number,
className: String, className: String,
customStyle: Object customStyle: Object

View File

@ -66,7 +66,7 @@ const PopupManager = {
const el = modal.$el; const el = modal.$el;
if (el.parentNode) { if (el.parentNode) {
el.parentNode.removeChild(el); modal.visible = false;
} }
if (context.top) { if (context.top) {
@ -75,7 +75,8 @@ const PopupManager = {
targetNode.appendChild(el); targetNode.appendChild(el);
Object.assign(modal, { Object.assign(modal, {
...modalDefaultConfig, ...modalDefaultConfig,
...config ...config,
visible: true
}); });
} }
} }

View File

@ -32,7 +32,7 @@ export default {
}, },
data() { data() {
const transition = this.transition || (this.position === '' ? 'popup-fade' : `popup-slide-${this.position}`); const transition = this.transition || (this.position === '' ? 'van-fade' : `popup-slide-${this.position}`);
return { return {
currentValue: false, currentValue: false,
currentTransition: transition currentTransition: transition

View File

@ -1,5 +1,5 @@
<template> <template>
<transition name="van-toast-fade"> <transition name="van-fade">
<div class="van-toast-wrapper" v-show="visible"> <div class="van-toast-wrapper" v-show="visible">
<div class="van-toast" :class="[`van-toast--${displayStyle}`, `van-toast--${position}`]"> <div class="van-toast" :class="[`van-toast--${displayStyle}`, `van-toast--${position}`]">
<!-- text only --> <!-- text only -->

View File

@ -19,6 +19,25 @@
} }
} }
@keyframes van-fade-out {
from {
opacity: 1;
}
to {
opacity: 0;
}
}
.van-fade {
&-enter-active {
animation: .3s van-fade-in;
}
&-leave-active {
animation: .3s van-fade-out;
}
}
.van-slide-bottom { .van-slide-bottom {
&-enter-active { &-enter-active {
animation: van-slide-bottom-enter .3s both ease; animation: van-slide-bottom-enter .3s both ease;

View File

@ -8,7 +8,6 @@
top: 0; top: 0;
left: 0; left: 0;
background-color: rgba(0, 0, 0, 0.7); background-color: rgba(0, 0, 0, 0.7);
animation: van-fade-in .3s both;
} }
&-overflow-hidden { &-overflow-hidden {
@ -77,7 +76,3 @@
.popup-slide-left-enter, .popup-slide-left-leave-active { .popup-slide-left-enter, .popup-slide-left-leave-active {
transform: translate3d(-100%, -50%, 0); transform: translate3d(-100%, -50%, 0);
} }
.popup-fade-enter, .popup-fade-leave-active {
opacity: 0;
}

View File

@ -17,10 +17,6 @@
transform: translate3d(-50%, -50%, 0); transform: translate3d(-50%, -50%, 0);
background-color: rgba(39, 39, 39, .7); background-color: rgba(39, 39, 39, .7);
&-wrapper {
transition: opacity .2s;
}
&__overlay { &__overlay {
position: fixed; position: fixed;
top: 0; top: 0;
@ -68,7 +64,3 @@
bottom: 50px; bottom: 50px;
} }
} }
.van-toast-fade-enter, .van-toast-fade-leave-to {
opacity: 0;
}

View File

@ -97,7 +97,7 @@ describe('Toast', () => {
setTimeout(() => { setTimeout(() => {
expect(document.querySelector('.van-toast-wrapper').style.display === 'none').to.be.true; expect(document.querySelector('.van-toast-wrapper').style.display === 'none').to.be.true;
done(); done();
}, 300); }, 500);
}); });
it('toast duration 0', (done) => { it('toast duration 0', (done) => {