L&Z's blog L&Z's blog
主页
  • HTML
  • CSS
  • JS
  • TS
  • Vue
  • Node
  • Markdown
  • Yaml
  • HTML
  • CSS
  • JS
  • TS
  • Vue
  • Node
  • 小程序
  • 博客
  • 工作
  • VSCode
  • Browser
  • Npm
  • Git
  • GitHub
  • 友链
  • 收藏
  • 足迹
  • 记录
  • 抽奖
  • 错 or 对
  • 分类
  • 标签
  • 归档
关于
GitHub (opens new window)

L&Z

主页
  • HTML
  • CSS
  • JS
  • TS
  • Vue
  • Node
  • Markdown
  • Yaml
  • HTML
  • CSS
  • JS
  • TS
  • Vue
  • Node
  • 小程序
  • 博客
  • 工作
  • VSCode
  • Browser
  • Npm
  • Git
  • GitHub
  • 友链
  • 收藏
  • 足迹
  • 记录
  • 抽奖
  • 错 or 对
  • 分类
  • 标签
  • 归档
关于
GitHub (opens new window)
  • CSS

  • JS

  • Vue

    • 基础

    • 组件

    • 过渡&动画

      • transition过渡&动画
      • 使用animate库
      • transition-group列表过渡
        • 列表的进入/离开过渡
        • 列表的排序过渡
          • 列表过渡&排序过渡
    • 可复用性&组合

    • 工具

    • 规模化

    • Vuex

    • Axios 常用配置
    • Vue中的防抖函数封装和使用
    • 操作本地缓存
  • Node

  • 小程序

  • 博客搭建

  • 工作

  • 笔记
  • Vue
  • 过渡&动画
lz
2021-08-04
目录
列表的进入/离开过渡
列表的排序过渡
列表过渡&排序过渡

transition-group列表过渡

# 列表的进入/离开过渡

<transition-group tag="ul"> <!--tag转为ul-->
    <li v-for="item in list" :key="item">{{item}}</li> <!--子元素要有key-->
</transition-group>
1
2
3

注意:列表元素一定要有key

.v-enter,.v-leave-to{
  opacity: 0;
  transform: translateX(30px);
}
.v-enter-active,.v-leave-active{
  transition: all 1s;
}
1
2
3
4
5
6
7
<div id="root">
    <button @click="handleAdd">Add</button>
    <button @click="handleRemove">Remove</button>
    <transition-group tag="ul">
      <li v-for="item in list" :key="item">{{item}}</li>
    </transition-group>
</div>

<style>
  .v-enter,.v-leave-to{
  opacity: 0;
  transform: translateX(30px);
}
.v-enter-active,.v-leave-active{
  transition: all 1s;
}
</style>

<script>
const vm = new Vue({
  el: '#root',
  data: {
    list: [1,2,3]
    },
  methods: {
    handleAdd() {
      this.list.push(this.list.length + 1)
    },
    handleRemove() {
      this.list.pop()
    }
  }
})
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

# 列表的排序过渡

.v-move {
  transition: transform 1s;
}
1
2
3
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.14.1/lodash.min.js"></script>

<div id="root">
    <button @click="shuffle">洗牌</button>
    <transition-group tag="ul">
      <li v-for="item in list" :key="item">{{item}}</li>
    </transition-group>
</div>

<style>
.v-move {
  transition: transform 1s;
}
</style>

<script>
var vm = new Vue({
  el: '#root',
  data: {
    list: [1,2,3,5,6,7,8]
  },
  methods: {
    shuffle: function () {
      this.list = _.shuffle(this.list)
    }
  }
})
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

# 列表过渡&排序过渡

<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.14.1/lodash.min.js"></script>

<div id="list-complete-demo" class="demo">
  <button v-on:click="shuffle">Shuffle</button>
  <button v-on:click="add">Add</button>
  <button v-on:click="remove">Remove</button>
  <transition-group name="list-complete" tag="p">
    <span
      v-for="item in items"
      v-bind:key="item"
      class="list-complete-item"
    >
      {{ item }}
    </span>
  </transition-group>
</div>

<style>
.list-complete-item {
  transition: all 1s;
  display: inline-block;
  margin-right: 10px;
}
.list-complete-enter, .list-complete-leave-to{
  opacity: 0;
  transform: translateY(30px);
}
.list-complete-leave-active {
  position: absolute;
}
</style>

<script>
new Vue({
  el: '#list-complete-demo',
  data: {
    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)
    },
    shuffle: function () {
      this.items = _.shuffle(this.items)
    }
  }
})
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
编辑 (opens new window)
#Vue
上次更新: 2023/03/08, 02:53:55
使用animate库
Mixin混入

← 使用animate库 Mixin混入→

最近更新
01
nodejs递归读取所有文件
12-15
02
vue3响应式原理
09-20
03
原生js实现jquery中siblings效果
09-20
更多文章>
Theme by Vdoing | Copyright © 2021-2025 L&Z |
  • 跟随系统
  • 浅色模式
  • 深色模式