当前位置: 首页 > news >正文

uniapp uni.createAnimation为文件交换位置动画效果

需求:

采用uni.createAnimation,为文件列表调换位置添加动画效果

效果图

在这里插入图片描述

代码

<view><view class="section-title">修改前</view><view class="file-section" :animation="animationData1">业务内容代码。。。</view><view class="section-title">修改后</view><view class="file-section" :animation="animationData2">业务内容代码。。。</view><button @click="swap">交换位置</button>
</view>
const animationData1 = ref(null);
const animationData2 = ref(null);
const isAnimating = ref(false);
const fileList = ref([]); //文件列表// 创建动画实例
function createAnimation() {const animation1 = uni.createAnimation({duration: 300,timingFunction: 'linear',delay: 0});const animation2 = uni.createAnimation({duration: 300,timingFunction: 'linear',delay: 0});return { animation1, animation2 };
}function swap() {isAnimating.value = true;// 获取元素位置信息const query = uni.createSelectorQuery();query.selectAll('.file-section').boundingClientRect(data => {if (!data || data.length < 2) {isAnimating.value = false;return;}const [section1Rect, section2Rect] = data;const { animation1, animation2 } = createAnimation();// 计算相对位移const moveY1 = section2Rect.top - section1Rect.top;const moveY2 = section1Rect.top - section2Rect.top;// 应用动画animation1.translateY(moveY1).step();animation2.translateY(moveY2).step();animationData1.value = animation1.export();animationData2.value = animation2.export();// 动画结束后交换数据setTimeout(() => {// 交换数据fileList = fileList.reverse()// 重置动画状态animation1.translateY(0).step({ duration: 0 });animation2.translateY(0).step({ duration: 0 });animationData1.value = animation1.export();animationData2.value = animation2.export();isAnimating.value = false;}, 1000);}).exec();
}onMounted(() => {// 初始化动画数据const { animation1, animation2 } = createAnimation();animationData1.value = animation1.export();animationData2.value = animation2.export();
});
http://www.dtcms.com/a/243157.html

相关文章:

  • Uniapp实现多选下拉框
  • Linux C学习路线全概括及知识点笔记3-网络编程
  • uniapp音乐播放createInnerAudioContext
  • # include<heαd.h>和# include″heαd.h″的区别
  • Argocd 运维与最佳实践
  • 【uniapp】小程序中input输入框的placeholder-class不生效
  • 【C++】来学习使用set和map吧
  • matlab分布式电源微电网潮流
  • DAS-U250高性能分布式光纤声波传感器
  • Spring @Scope, @Lazy, @DependsOn, @Required, @Lookup
  • 机器学习核心概念速览
  • Springboot项目的目录结构
  • AI赋能Automa二次开发
  • Spring @Qualifier,@Primary
  • 分布式ID实现方案实战示例总结
  • 【Zephyr 系列 18】分布式传感网络系统设计:从 BLE Mesh 到边缘网关的数据闭环
  • 看安科瑞分布式光伏解决方案如何破解光伏痛点?
  • 机器学习赋能的智能光子学器件系统研究与应用
  • 基于生成对抗网络(GAN)的图像生成与编辑:原理、应用与实践
  • Idea 2025 commit 关闭侧边栏 开启探框
  • SHA-1算法详解:原理、特点与应用
  • OctoPrint公网部署如何实现?3D打印远程控制一键部署过程!
  • 牛市与熊市:市场周期的双面镜
  • 记录下three.js学习过程中不理解问题----材质(material)⑤
  • NLP学习路线图(三十九):对话系统
  • 2025年渗透测试面试题总结-长亭科技[实习]安全服务工程师题目+回答)
  • 如何将文件从 iPhone 传输到闪存驱动器
  • GaussDB分布式数据库调优方法总结:从架构到实践的全链路优化指南
  • 增强现实—Flame: Learning to navigate with multimodal llm in urban environments
  • 安全生产管理是什么?安全生产管理主要管什么?