小编vie*_*ist的帖子

Vue Transition-Group - 如何防止“跳跃”?

我有两个div,我使用transition-group在它们之间进行转换,它的工作原理应该是这样的——但是,div转换下方的内容是“跳跃”的,具体取决于div的高度。我想要的是阻止跳跃,而是以某种方式进行动画处理,这样在元素之间切换时我会得到一个很好的平滑过渡,而不会“推”到带有“跳跃”的内容。

希望这是有道理的:)

我在这里设置了codesandbox的示例: https: //codesandbox.io/s/reverent-stallman-8ixhp ?file=/src/components/HelloWorld.vue

模板如下所示:

<div class="hello">
    <button @click="groupShowOne">Show first {{ gShowFirst }}</button>
    <button @click="groupShowTwo">Show second {{ gShowSecond }}</button>
    <transition-group name="fade-group" tag="div" mode="out-in" appear>
      <div
        class="group-element"
        v-if="gShowFirst"
        style="background-color: yellow"
      >
        <h3>This is a headline</h3>
        <p>This is a text</p>
      </div>
      <div
        class="group-element"
        v-if="gShowSecond"
        style="background-color: red"
      >
        <h3>
          This is a headline <br />This is a headline <br />This is a headline
          This is a headline This is a headline This is a headline
        </h3>
        <p>
          This is a text …
Run Code Online (Sandbox Code Playgroud)

vue.js vuejs2 vue-transitions vuejs3

5
推荐指数
1
解决办法
4740
查看次数

标签 统计

vue-transitions ×1

vue.js ×1

vuejs2 ×1

vuejs3 ×1