【发布时间】:2018-09-25 20:34:50
【问题描述】:
所以我很难理解为什么没有mode="out-in" 转换不会从上到下滚动。
使用out-in,它会按预期滚动(尽管有延迟),但没有out-in,它会滚动下来,然后突然出现。
这是我的密码箱:https://codesandbox.io/s/2zlr154m1r
Vue 文件供将来参考:
App.vue
<template>
<div id="app">
<button @click="toggleExamples">switched</button>
<div class="wrapper">
<transition name="rolling-down">
<component :is="which" />
</transition>
</div>
<br>
<div class="wrapper">
<transition name="rolling-down" mode="out-in">
<component :is="other" />
</transition>
</div>
</div>
</template>
<script>
import HelloWorld from "./components/HelloWorld";
import Example1 from "./components/Example1";
import Example2 from "./components/Example2";
export default {
name: "App",
components: {
"example-one": Example1,
"example-two": Example2,
HelloWorld
},
data() {
return {
which: "example-one",
other: "example-two"
};
},
methods: {
toggleExamples() {
let array = ["example-one", "example-two"];
this.which = array[+(this.which === "example-one")];
this.other = array[+(this.other === "example-one")];
}
}
};
</script>
<style>
#app {
font-family: "Avenir", Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
text-align: center;
color: #2c3e50;
margin-top: 60px;
}
.rolling-down-enter-active,
.rolling-down-leave-active {
transition: all 0.5s ease;
}
.rolling-down-enter {
transform: translateY(-100%);
}
.rolling-down-enter-to {
transform: translateY(0);
}
.rolling-down-leave {
transform: translateY(0);
}
.rolling-down-leave-to {
transform: translateY(100%);
}
.wrapper {
border: 2px solid black;
overflow: hidden;
height: 30vh;
}
</style>
Example1.vue
<template>
<div class="parent">
example1
</div>
</template>
<script>
export default {};
</script>
<style lang="scss" scoped>
.parent {
height: 30vh;
width: 100vw;
background-color: red;
}
</style>
Example2.vue
<template>
<div class="parent">
this is example2
asfads
</div>
</template>
<script>
export default {};
</script>
<style lang="scss" scoped>
.parent {
height: 30vh;
width: 100vw;
background-color: blue;
}
</style>
【问题讨论】:
标签: javascript vue.js vuejs2 css-transitions vue-component