显示和隐藏元素列表时页面其余部分的平滑 Nuxt/Vue 过渡

smooth Nuxt/Vue transition on the rest of the page when displaying and hidding a list of elements

我得到了一个网格项目列表,以及一个在 "see more" 和 "see less" 之间切换的按钮。单击 "see more" 按钮,将显示所有列表。单击少看,仅显示 3 个项目。当显示所有项目时我们得到了一个很好的过渡,但是当我们隐藏它们时,底部的所有元素都不会跟随运动。我怎样才能使过渡平滑并且不让用户停留在段落中间?

模板示例:

<div>
  <transition-group name="list" class="grid">
      <div v-for="(content,index) in contents" :key="index" class="card">
        <h4>
          {{index}}
        </h4>
      </div>
  </transition-group>

  <button @click="onClickSeeButton">
    {{ seeButton }}
  </button>

  <p>
      Some text...
  </p>
</div>

我使用那些 css 属性进行转换

.list-enter-active, .list-leave-active {
  transition: all 1s;
}
.list-enter, .list-leave-to {
  opacity: 0;
}

脚本如下:

new Vue({
  el: "#app",
  data: {
    els: [1,2,3,4,5,6,7,8,9,10,11,12], // from 0 to infinite
    seeMore: true
  },
  computed: {
    contents: function(){
        return this.seeMore ? this.els.filter((el,index) => index < 3 ) : this.els
    },
    readButton: function(){
        return this.seeMore ? 'see more' : 'see less'
    }
  },
  methods: {
    onClickReadButton: function(){
        this.seeMore = !this.seeMore
    }
  }
})

https://jsfiddle.net/ghivalla/v5me216c/3/

试试这个

.list-enter-active, .list-leave-active {
  transition: all 1s;
  opacity: 1;
}
.list-enter, .list-leave-to {
  opacity: 0; height: 0;
}

https://jsfiddle.net/w4v9g6us/

这里也是阅读更多关于 vue 和转换的好地方 https://vuejs.org/v2/guide/transitions.html