# 设置动画为初次载入就播放

Demo1
Demo2
Demo3
Demo4
Demo5
<template>
  <db-transition-group class-name="fadeInLeft" first-play>
    <div v-for="item in list" :key="item" style="margin-top:10px;">
      <db-button>{{item}}</db-button>
    </div>
  </db-transition-group>
</template>
<script>
export default {
  data () {
    return {
      list: [
        'Demo1',
        'Demo2',
        'Demo3',
        'Demo4',
        'Demo5'
      ]
    }
  }
}
</script>
Expand Copy

# 设置动画延迟

  • 有些时候我们需要让动画延时一定时间在进行可使用entrance-time这个参数来设定
Demo1
Demo2
Demo3
Demo4
Demo5
<template>
  <db-transition-group class-name="fadeInLeft" first-play :entrance-time="2000">
    <div v-for="item in list" :key="item" style="margin-top:10px;">
      <db-button>{{item}}</db-button>
    </div>
  </db-transition-group>
</template>
<script>
export default {
  data () {
    return {
      list: [
        'Demo1',
        'Demo2',
        'Demo3',
        'Demo4',
        'Demo5'
      ]
    }
  }
}
</script>
Expand Copy

# 动画时长

  • duration可以来设置动画的显示时长
Demo1
Demo2
Demo3
Demo4
Demo5
<template>
  <db-transition-group class-name="db_left_show" first-play :duration="10000" >
    <div v-for="item in list" :key="item" style="margin-top:10px;">
      <db-button>{{item}}</db-button>
    </div>
  </db-transition-group>
</template>
<script>
export default {
  data () {
    return {
      list: [
        'Demo1',
        'Demo2',
        'Demo3',
        'Demo4',
        'Demo5'
      ]
    }
  }
}
</script>
Expand Copy

# 手动触发动画

触发
Demo1
Demo2
Demo3
Demo4
Demo5
<template>
  <div>
    <db-button @click="click">触发</db-button>
    <db-transition-group class-name="db_left_show" ref="group">
      <div v-for="item in list" :key="item" style="margin-top:10px;">
        <db-button>{{item}}</db-button>
      </div>
    </db-transition-group>
  </div>
</template>
<script>
export default {
  data () {
    return {
      list: [
        'Demo1',
        'Demo2',
        'Demo3',
        'Demo4',
        'Demo5'
      ]
    }
  },
  methods: {
    click() {
      this.$refs.group.play()
    }
  }
}
</script>
Expand Copy

# 使用name

  • db-transiton-group 本身就是继承transiton-group所以他能继承transiton-group所有的特性你可以完全把他当前transiton-group来使用
Add Remove 1 2 3 4 5 6 7 8 9
<template>
  <div id="list-demo" class="demo">
    <db-button v-on:click="add">Add</db-button>
    <db-button v-on:click="remove">Remove</db-button>
    <db-transition-group name="list" tag="p">
      <span v-for="item in items" v-bind:key="item" class="list-item">
        {{ item }}
      </span>
    </db-transition-group>
  </div>
</template>
<script>
export default {
  data(){
    return {
    items: [1,2,3,4,5,6,7,8,9],
    nextNum: 10
  }
  },
  methods: {
    randomIndex: function () {
      return Math.floor(Math.random() * this.items.length)
    },
    add: function () {
      this.items.splice(this.randomIndex(), 0, this.nextNum++)
    },
    remove: function () {
      this.items.splice(this.randomIndex(), 1)
    },
  }
}
</script>
<style>
.list-item {
  display: inline-block;
  margin-right: 10px;
}
.list-enter-active, .list-leave-active {
  transition: all 1s;
}
.list-enter, .list-leave-to
/* .list-leave-active for below version 2.1.8 */ {
  opacity: 0;
  transform: translateY(30px);
}
</style>
Expand Copy