【问题标题】:vue transition, not rolling as intended without mode="out-in"vue 过渡,没有 mode="out-in" 时不会按预期滚动
【发布时间】: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


    【解决方案1】:

    我意识到它是什么。这是因为该元素实际上出现在离开元素的旁边,但由于它的定位,它出现在下方。

    https://codesandbox.io/s/ykqq6oov6j

    要解决它,您需要将position: absolute 应用于过渡组件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-10-30
      • 1970-01-01
      • 2012-02-15
      • 2021-05-30
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      • 1970-01-01
      相关资源
      最近更新 更多