【发布时间】:2019-06-13 02:13:09
【问题描述】:
我正在做一个项目,我必须渲染一些带有进入和离开动画的组件,当一个组件进入屏幕时,它必须从底部进入,当它离开时,它必须向上移动,期望的行为是,当我更改组件标签的 :is 属性时,当前组件向上,下一个从底部开始,代码如下所示:
<template>
<div class="home">
<transition name="section">
<component :is="activeSection"></component>
</transition>
</div>
</template>
<script>
import comp1 from './comp1';
import comp2 from './comp2';
export default {
components: {
comp1,
comp2
},
data() {
activeSection: 'comp1'
}
</script>
<style scoped>
.section-enter {
top: 100vh;
}
.section-enter-to {
top: 0vh;
}
.section-enter-active {
animation-name: 'slideIn';
animation-duration: 1s;
}
.section-leave {
top: 0vh;
}
.section-leave-active {
animation-name: 'slideOut';
animation-duration: 1s;
}
.section-leave-to {
top: -100vh;
}
@keyframes slideIn {
from {
top: 100vh;
}
to {
top: 0
}
}
@keyframes slideOut {
from {
top: 0vh;
}
to {
top: -100vh;
}
}
</style>
但实际行为是第一个组件向上,但第二个组件在没有动画的情况下立即出现。
如果我一次渲染一个(不破坏一个并用相同的动作渲染另一个)一切都很好。我不知道发生了什么。
【问题讨论】:
-
你能不能把它放在codesandbox之类的地方,这样更容易重新创建和查看?
-
嘿,在我的例子中,我只需要在我的转换中添加一个
appear属性。希望它可以帮助其他有这个问题的人!
标签: javascript css animation vue.js vuejs2