animation-list vue 元素列表动画渲染

animation-list

简介

https://i-blog.csdnimg.cn/blog_migrate/921f9465bef45e1bd523abb0ad736243.gif#pic_center

  • animation-list 基于vue列表动画插件,支持vue3.0

引用

  • 安装
npm i animation-list
  • 例子
<template>
  <AnimationList ref="animationListRef">
    <div class="item" v-for="item in 8" :key="item">{{ item }}</div>
  </AnimationList>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import AnimationList from 'animation-list/AnimationList.vue'
const animationListRef = ref<InstanceType<typeof AnimationList>>()
onMounted(() => {
  animationListRef.value?.initHooks({
    end: () => {
        console.log('动画结束')
        animationListRef.value?.animationCall() // 重新触发动画
    }
  })
})
</script>

<style  scoped>
.list {
  display: flex;
  flex-wrap: wrap;
  text-align: center;
  line-height: 50px;
}
.list .item {
  width: 100px;
  height: 50px;
  border: 1px solid gainsboro;
  margin: 5px;
  box-shadow: 4px 5px 9px gainsboro;
  color: gray;
  border-radius: 4px;
}
</style>

参数

属性

参数默认值备注
firstShowtrue默认是否渲染动画
deepfalse是否深层查找
animationTypeANIMATION_TYPE.RIGHT_LEFT默认从右到左动画

ANIMATION_TYPE默认动画

key动画效果备注
BOTTOM_TOPbottom-top从下向上
TOP_BOTTOMtop-bottom从上向下
RIGHT_LEFTright-left从右到左默认
LEFT_RIGHTleft-right从左到右
SAMLL_BIGsmall-big从小到大
BIG_SMALLbig-small从大到小
CUSTOMcustom自定义动画根据例子自定义动画

异步渲染流程

// 1.设置属性取消默认渲染动画 firstShow
// 2.获取数据后重新触发
import { onMounted, ref,nextTick } from 'vue'
setTimeout(() => {
    // 获取数据
    nextTick(() => {
        animationListRef.value?.reAnimationList()
    })
}, 1500)

自定义动画

<template>
<AnimationList ref="animationListRef" :animationType="ANIMATION_TYPE.CUSTOM">
    <div class="item" v-for="item in 8" :key="item">{{ item }}</div>
    </AnimationList>
</template>
<script lang="ts" setup>
    import AnimationList from 'animation-list/AnimationList.vue'
    import { ANIMATION_TYPE } from 'animation-list/index.d'

</script>

<style  scoped>
    .list {
        display: flex;
        flex-wrap: wrap;
        text-align: center;
        line-height: 50px;
    }
    .list .item {
        width: 100px;
        height: 50px;
        border: 1px solid gainsboro;
        margin: 5px;
        box-shadow: 4px 5px 9px gainsboro;
        color: gray;
        border-radius: 4px;
    }
    /** 自定义动画部分(必须) **/
    .ls-custom {
        display: block;
        opacity: 1 !important;
    }
    .ls-custom {
        animation: ls-custom ease 0.26s !important;
    }
    @keyframes ls-custom {
        0% {
            opacity: 0;
            transform: scale(1.6);
        }
        100% {
            opacity: 1;
            transform: scale(1);
        }
    }

</style>
  • 在 style 样式加入
    • ls-custom 初始化
    • ls-custom 动画开始
    • keyframes 动画

hooks生命周期

animationListRef.value?.initHooks({
    start:()=>{},
    update:()=>{},
    end:()=>{}
})

  • 1.x.x - vue2 相关文档,请以该版本的 README 为准

  • 2.1.x - vue3

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tommyrunner

你的支持,就是我的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值