当前位置: 首页 > 编程日记 > 正文

无限循环动画实现

先来个效果图

示例代码是先缩小移动,然后无限循环左右晃动,希望能够帮助到你,点个赞吧~

实现代码

	<image class="element1" @load="element1_load" :animation="animationData" src="../../static/element1.png" mode="widthFix"></image>

JS

var animation, that, ani_start_time=600;data() {return {animationData: {},animation: {},}},onLoad(option) {that = this},methods: {element1_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 1}//设置循环动画animation.translateX(80).scale(.34, .34).step({duration: ani_start_time,delay: 10})this.animationData = animation.export()var next = true;setTimeout(() => {setInterval(() => {if (next) {animation.rotate(3).step(data)} else {animation.rotate(-3).step(data)}next = !next;this.animationData = animation.export()}, 150)}, ani_start_time)},}

看一下完整代码页面的效果图

代码

<template><view><!-- <sliderBar max='90' min='20' @change='change'></sliderBar> --><image class="bg" mode="widthFix"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/1_bg.png"></image><image class="title_img" @load="title_load" :animation="animationData_title_img"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/1_title.png" mode="widthFix"></image><image v-if="a_show" class="element1" @load="element1_load" :animation="animationData"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/element1.png" mode="widthFix"></image><image v-if="b_show" class="element2" @load="element2_load" :animation="animationData2"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/element2.png" mode="widthFix"></image><image v-if="c_show" class="element3" @load="element3_load" :animation="animationData3"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/element3.png" mode="widthFix"></image><image v-if="d_show" class="element4" @load="element4_load" :animation="animationData4"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/element4.png" mode="widthFix"></image><image @load="btn_load" :animation="animationData_btn"  class="btnImg" mode="widthFix" @click="nav"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/1_btn.png"></image></view></template><script>var that;var ani_start_time = 400,delay=300;import sliderBar from "@/components/sliderBar.vue"export default {components: {sliderBar},data() {return {a_show:false,b_show:false,c_show:false,d_show:false,animationData_btn:false,animationData: {},animationData2: {},animationData3: {},animationData4: {},anima_if: false,show_gou: false,animationData_title_img: {},}},onLoad(option) {that = thissetTimeout(()=>{this.a_show=true},500)setTimeout(()=>{this.b_show=true},1000)setTimeout(()=>{this.c_show=true},1500)setTimeout(()=>{this.d_show=true},2000)},methods: {// 按钮加载完成btn_load() {console.log('按钮加载完成')setTimeout(()=>{var animation_btn = uni.createAnimation({duration: ani_start_time*7.5,timingFunction: 'linear',delay: delay})animation_btn.translateY(-120).step()this.animationData_btn = animation_btn.export()var data = {duration: 450,timingFunction: 'linear',delay: 1}var next = true;setTimeout(() => {setInterval(() => {if (next) {animation_btn.scale(1.05).step(data)} else {animation_btn.scale(0.95).step(data)}next = !next;this.animationData_btn = animation_btn.export()}, 450)}, ani_start_time*7.5)},2300)},// 标题图片加载完成title_load() {console.log('标题图片加载完成')setTimeout(()=>{var animation_title_img = uni.createAnimation({duration: ani_start_time,timingFunction: 'linear',delay: delay})animation_title_img.translateX(-510).step()animation_title_img.translateX(-500).step()animation_title_img.translateX(-505).step()this.animationData_title_img = animation_title_img.export()},2100)},element2_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 1}//设置循环动画animation.translateX(50).scale(.34, .34).step({duration: ani_start_time,delay: delay})var next = true;setTimeout(() => {setInterval(() => {if (next) {animation.rotate(3).step(data)} else {animation.rotate(-3).step(data)}next = !next;this.animationData2 = animation.export()}, 150)}, ani_start_time)},element3_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 1}//设置循环动画animation.translateX(-80).scale(.34, .34).step({duration: ani_start_time,delay: delay})var next = true;setTimeout(() => {setInterval(() => {if (next) {animation.rotate(3).step(data)} else {animation.rotate(-3).step(data)}next = !next;this.animationData3 = animation.export()}, 150)}, ani_start_time)},element4_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 1}//设置循环动画animation.translateX(-40).scale(.34, .34).step({duration: ani_start_time,delay: delay})var next = true;setTimeout(() => {setInterval(() => {if (next) {animation.rotate(3).step(data)} else {animation.rotate(-3).step(data)}next = !next;this.animationData4 = animation.export()}, 150)}, ani_start_time)},// 元素1加载完成element1_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 1}//设置循环动画this.animation = animationthis.animation.translateX(80).scale(.34, .34).step({duration: ani_start_time,delay: delay})this.animationData = animation.export()var next = true;setTimeout(() => {setInterval(() => {if (next) {this.animation.rotate(3).step(data)} else {this.animation.rotate(-3).step(data)}next = !next;this.animationData = animation.export()}, 150)}, ani_start_time)},nav() {this.$request(this.$api.Baby.babyList).then(res => {console.log(res)if (res.data.baby_list.length > 0) {var id = res.data.baby_list[0].id;let data = {baby_id: id}uni.setStorageSync('baby_id', id)this.$request(this.$api.Baby.babyGrowList, data).then(ress => {console.log('aaaaaaaaa', ress)if (ress.data.grow_info_list.length > 0) {var baby_birthday = ress.data.baby_info.baby_birthdayuni.setStorageSync('baby_birthday', baby_birthday)uni.navigateTo({url: '../babyGrowthRecord/babyGrowthRecord'})} else {uni.navigateTo({url: '../addGrowthRecord/addGrowthRecord'})}})} else {uni.reLaunch({url: '../addInfo/addInfo'})}})},}}
</script><style lang="scss" scoped>.bg {width: 100%;}img {display: block;}.element1 {position: absolute;top: 140rpx;right: 0;width: 420rpx;height: 420rpx;z-index: 2;}.element2 {position: absolute;top: 490rpx;right: 30rpx;width: 320rpx;height: 320rpx;z-index: 2;}.element3 {position: absolute;top: 740rpx;left: 180rpx;width: 280rpx;height: 280rpx;z-index: 2;}.element4 {position: absolute;top: 690rpx;left: 0;width: 240rpx;height: 240rpx;z-index: 2;}.title_img {position: absolute;top: 30rpx;right: -950rpx;width: 96%;z-index: 2;}.btnImg {position: absolute;bottom: -100rpx;left: 15%;width: 70%;height: 80rpx;z-index: 2;// background-color: red;}.bottomBlock {position: relative;.gou_block {position: absolute;bottom: 20rpx;width: 40%;left: 30%;height: 60rpx;}.home_gou {width: 46rpx;position: absolute;bottom: 20rpx;left: 11%;}}
</style>

第三版本

效果图

<template><view><!-- <sliderBar max='90' min='20' @change='change'></sliderBar> --><image class="bg" mode="widthFix"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/1_bg1.png"></image><image class="bg3" mode="widthFix"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/1_bg33.gif"></image><image class="bg2" mode="widthFix"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/1_bg2.png"></image><image class="title_img" @load="title_load" :animation="animationData_title_img"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/1_title.png" mode="widthFix"></image><image v-if="a_show" :class="!animationData?'anima':''" class="element1 " @load="element1_load" :animation="animationData"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/element1.png" mode="widthFix"></image><image v-if="b_show" :class="!animationData2?'anima':''" class="element2 " @load="element2_load" :animation="animationData2"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/element2.png" mode="widthFix"></image><image v-if="c_show" :class="!animationData3?'anima':''" class="element3 " @load="element3_load" :animation="animationData3"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/element3.png" mode="widthFix"></image><image v-if="d_show" :class="!animationData4?'anima':''" class="element4 " @load="element4_load" :animation="animationData4"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/element4.png" mode="widthFix"></image><image v-if="btn_show" class="btnImg anima" mode="widthFix" @click="nav"src="cloud://yun-6g7hq5oz4c910180.7975-yun-6g7hq5oz4c910180-1305191802/static/1_btn.png"></image></view></template><script>var that;var ani_start_time = 400,delay = 300;import sliderBar from "@/components/sliderBar.vue"export default {components: {sliderBar},data() {return {a_show: false,b_show: false,c_show: false,d_show: false,btn_show: false,animationData_btn: false,animationData: {},animationData2: {},animationData3: {},animationData4: {},anima_if: false,show_gou: false,animationData_title_img: {},}},onLoad(option) {that = thissetTimeout(() => {this.a_show = true}, 500)setTimeout(() => {this.b_show = true}, 1000)setTimeout(() => {this.c_show = true}, 1500)setTimeout(() => {this.d_show = true}, 2000)setTimeout(() => {this.btn_show = true}, 4400)},methods: {// 元素1加载完成element1_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 1}animation.translateX(-510).step(data)this.animationData = animation.export()setTimeout(() => {animation.translateX(0).step(data)this.animationData = animation.export()}, 150)setTimeout(() => {				this.animationData=false}, 300)},// 标题图片加载完成title_load() {console.log('标题图片加载完成')setTimeout(() => {var animation_title_img = uni.createAnimation({duration: ani_start_time,timingFunction: 'linear',delay: delay})animation_title_img.translateX(-500).step()animation_title_img.translateX(-490).step()animation_title_img.translateX(-495).step()this.animationData_title_img = animation_title_img.export()}, 2000)},element2_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 1}animation.translateX(-510).step(data)this.animationData2 = animation.export()setTimeout(() => {animation.translateX(0).step(data)this.animationData2 = animation.export()}, 150)setTimeout(() => {				this.animationData2 =false}, 300)},element3_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 1}animation.translateX(-510).step(data)this.animationData3 = animation.export()setTimeout(() => {animation.translateX(0).step(data)this.animationData3 = animation.export()}, 150)setTimeout(() => {				this.animationData3=false}, 300)},element4_load() {var animation = wx.createAnimation({})var data = {duration: 150,timingFunction: 'linear',delay: 0}animation.translateX(-510).step(data)this.animationData4 = animation.export()setTimeout(() => {animation.translateX(0).step(data)this.animationData4 = animation.export()}, 150)setTimeout(() => {				this.animationData4=false}, 300)},nav() {this.$request(this.$api.Baby.babyList).then(res => {console.log(res)if (res.data.baby_list.length > 0) {var id = res.data.baby_list[0].id;let data = {baby_id: id}uni.setStorageSync('baby_id', id)this.$request(this.$api.Baby.babyGrowList, data).then(ress => {console.log('aaaaaaaaa', ress)if (ress.data.grow_info_list.length > 0) {var baby_birthday = ress.data.baby_info.baby_birthdayuni.setStorageSync('baby_birthday', baby_birthday)uni.navigateTo({url: '../babyGrowthRecord/babyGrowthRecord'})} else {uni.navigateTo({url: '../addGrowthRecord/addGrowthRecord'})}})} else {uni.reLaunch({url: '../addInfo/addInfo'})}})},}}
</script><style lang="scss" scoped>.bg {width: 100%;z-index: -1;position: absolute;top: 0;}.bg3 {width: 100%;z-index: 1;position: absolute;top: 240rpx;}.bg2 {width: 100%;z-index: 1;position: absolute;top: 310rpx;}img {display: block;}.element1 {position: absolute;top: 260rpx;right: 0;width: 120rpx;height: 120rpx;z-index: 2;}.element2 {position: absolute;top: 640rpx;right: 40rpx;width: 100rpx;height: 100rpx;z-index: 2;}.element3 {position: absolute;top: 820rpx;left: 100rpx;width: 110rpx;height: 110rpx;z-index: 2;}.element4 {position: absolute;top: 790rpx;left: 0;width: 90rpx;height: 90rpx;z-index: 2;}.title_img {position: absolute;top: 30rpx;right: -950rpx;width: 96%;z-index: 2;}.btnImg {position: absolute;top: 990rpx;left: 15%;width: 70%;height: 80rpx;z-index: 2;// background-color: red;}.anima {animation-name: likes; // 动画名称animation-direction: alternate; // 动画在奇数次(1、3、5...)正向播放,在偶数次(2、4、6...)反向播放。animation-timing-function: linear; // 动画执行方式,linear:匀速;ease:先慢再快后慢;ease-in:由慢速开始;ease-out:由慢速结束;ease-in-out:由慢速开始和结束;animation-delay: 0s; // 动画延迟时间animation-iteration-count: infinite; //  动画播放次数,infinite:一直播放animation-duration: 1s; // 动画完成时间}@keyframes likes {0% {transform: scale(1);}25% {transform: scale(0.9);}50% {transform: scale(0.85);}75% {transform: scale(0.9);}100% {transform: scale(1);}}.bottomBlock {position: relative;.gou_block {position: absolute;bottom: 20rpx;width: 40%;left: 30%;height: 60rpx;}.home_gou {width: 46rpx;position: absolute;bottom: 20rpx;left: 11%;}}
</style>

相关文章:

利用属性封装复杂的选项

1、考虑这样一个场景。 我们的程序中有一个“选项”窗口&#xff0c;这个窗口包含很多选项。其中有一个选项是单选类型的&#xff0c;用户可以从N个选项值中选择一个。 我们需要在用户单击“确定”按钮后把用户选择的值保存到文件中&#xff0c;程序下次启动时再读取到内存中。…

react 渲染道具_关于React道具的另一篇文章

react 渲染道具You could say this topic has been done to death, but lately I’ve started using a technique that I dont recall having come across elsewhere. While its not particularly clever, it is concise. So please forgive one more post on the topic...你…

高可用集群的概念

一&#xff1a;什么是高可用集群 高可用集群&#xff08;High Availability Cluster&#xff0c;简称HA Cluster&#xff09;&#xff0c;是指以减少服务中断时间为目的得服务器集群技术。它通过保护用户得业务程序对外部间断提供的服务&#xff0c;把因为软件&#xff0c;硬件…

node.js 出现cannot find module ‘xxx‘ 解决办法

找不到模块的解决方案 &#xff1a; 把node_module整个文件夹删掉,然后npm clean cache,看下package.json里有没有express的依赖项,有的话直接npm install,没有的话 npm install express --save npm clean cache 如果不行的话用 npm cache clean

poj 1904 King's Quest

Kings Quest 题意&#xff1a;有N个王子和N个妹子;(1 < N < 2000)第i个王子喜欢Ki个妹子&#xff1b;(详见sample)题给一个完美匹配&#xff0c;即每一个王子和喜欢的一个妹子结婚&#xff1b;问每一个王子可以有几种选择(在自己喜欢的妹子里面选)&#xff0c;并输出可选…

数据预处理--噪声_为什么数据对您的业务很重要-以及如何处理数据

数据预处理--噪声YES! Data is extremely important for your business.是&#xff01; 数据对您的业务极为重要。 A human body has five sensory organs, and each one transmits and receives information from every interaction every second. Today, scientists can det…

C++ template

&#xff08;转自http://www.cnblogs.com/gw811/archive/2012/10/25/2738929.html&#xff09; C模板 模板是C支持参数化多态的工具&#xff0c;使用模板可以使用户为类或者函数声明一种一般模式&#xff0c;使得类中的某些数据成员或者成员函数的参数、返回值取得任意类型。 模…

js根据经纬度取随机附近经纬度

实现功能&#xff1a; 小程序根据当前经纬度得出随机的附近经纬度显示在地图上做标记点&#xff0c;效果图 实现代码 // map.js var app getApp() var mymap ; var lat ; var long ; var that;function latlog(lat, lon, d 1,d23) {var angle Math.random(1, 360);var …

讽刺笑话_完全不讽刺的2019年网络设计指南

讽刺笑话I’ve written about how to design for the modern web before, way back in 2018. But the web moves forward quickly so those guidelines are already obsolete and outdated, as more modern conventions have become mainstream.早在2018年&#xff0c;我就已经…

模拟城市2.0

题目背景 博弈正在机房颓一个叫做《模拟城市2.0》的游戏。 2048年&#xff0c;经过不懈努力&#xff0c;博弈终于被组织委以重任&#xff0c;成为D市市委书记&#xff01;他勤学好问&#xff0c;励精图治&#xff0c;很快把D市建设成富强民主文明和谐的美好城市。为了进一步深化…

bzoj:1221;vijos 1552 软件开发

Description 某软件公司正在规划一项n天的软件开发计划&#xff0c;根据开发计划第i天需要ni个软件开发人员&#xff0c;为了提高软件开发人员的效率&#xff0c;公司给软件人员提供了很多的服务&#xff0c;其中一项服务就是要为每个开发人员每天提供一块消毒毛巾&#xff0c;…

u-charts 曲线图中间有部分没数据,导致点和点无法连成线的问题解决

解决曲线图或者折线图在两端中间没有数据时无法绘画成线的问题源码修改, 解决方案: 在数据之间填充假数据,并且创建一个和点的数据同级的 list 来验证是不是假数据,如果是假数据就不绘制点,是真数据才绘制点,达到点和点之间没数据但是能连线的效果 先看效果图: 数据格…

python构建json_如何使用Python构建JSON API

python构建jsonThe JSON API specification is a powerful way for enabling communication between client and server. It specifies the structure of the requests and responses sent between the two, using the JSON format.JSON API规范是启用客户端和服务器之间通信的…

样式集 - 自适应居中弹窗

效果图&#xff1a; 弹窗1代码 <!-- 答题正确弹窗 --><block v-if"answer_true_show"><view class"answer_true_bg"></view><view class"answer_true"><img class"true_bg_img" :src"qualifyi…

struts2中 ServletActionContext与ActionContext区别

1. ActionContext 在Struts2开发中,除了将请求参数自动设置到Action的字段中,我们往往也需要在Action里直接获取请求(Request)或会话(Session)的一些信息,甚至需要直接对JavaServlet Http的请求(HttpServletRequest),响应(HttpServletResponse)操作. 我们需要在Action中取得req…

[记录]calculate age based on date of birth

calculate age based on date of birth know one new webiste:eval.in run php code转载于:https://www.cnblogs.com/fsong/p/5190273.html

有抱负的Web开发人员应考虑的6件事

Becoming a web developer can be as challenging as working out every day.成为网络开发人员就像每天锻炼一样具有挑战性。 It’s important to know what it will take to succeed as a web developer.重要的是要知道要成为一名Web开发人员要取得成功。 Here are 6 things…

阿里云OSS上传图片实现流程

前置&#xff0c;在阿里云开通OSS对象储存。然后在下图文件管理配置文件储存目录和图中传输管理配置访问域名。 1.复制 uploadFileUtil 文件夹和 uploadFile.js 文件在 util 文件夹 2.在使用的页面 引入 uploadFile 效果图&#xff1a; 实现代码 <template><view c…

修改远程桌面连接3389端口号

修改注册表&#xff1a; HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\Wds\Repwd\Tds\Tcp 键&#xff1a;PortNumber&#xff0c;以十进制显示&#xff1a;3389&#xff0c;修改成55555&#xff0c;保存刷新注册表。 HKEY_LOCAL_MACHINE\SYSTEM\Curre…

理解 : UDID、UUID、IDFA、IDFV

iOS获取设备唯一标识的各种方法&#xff1f;IDFA、IDFV、UDID分别是什么含义&#xff1f;iOS获取设备ID总结IDFA解释 关于UUID的理解 : 英文名称是&#xff1a;Universally Unique Identifier,翻译过来就是通用唯一标识符。 UUID是指在一台机器上生成的数字&#xff0c;它保证对…

推箱子2-向右推!_保持冷静,砍箱子-me脚

推箱子2-向右推!Hack The Box (HTB) is an online platform allowing you to test your penetration testing skills. It contains several challenges that are constantly updated. Some of them simulating real world scenarios and some of them leaning more towards a C…

H5面试题---介绍js的基本数据类型

js的基本数据类型 Undefined、Null、Boolean、Number、String 转载于:https://www.cnblogs.com/songchunmin/p/7789582.html

Node.js express 之mongoose 从异步回调函数返回值,类似于同步

http://my.oschina.net/antianlu/blog/187023转载于:https://www.cnblogs.com/cylblogs/p/5192314.html

小程序登录、用户信息相关接口调整说明

为&#xfeff;优化用户的使用体验&#xff0c;平台将进行以下调整&#xff1a; 2021年2月23日起&#xff0c;若小程序已在微信开放平台进行绑定&#xff0c;则通过wx.login接口获取的登录凭证可直接换取unionID2021年4月13日后发布的小程序新版本&#xff0c;无法通过wx.getU…

小程序 reduce_使用Reduce制作的10个JavaScript实用程序功能

小程序 reduceThe multi-tool strikes again. 多功能工具再次触击。 In my last article I offered you a challenge to recreate well-known functions using reduce. This article will show you how some of them can be implemented, along with some extras! 在上一篇文章…

流媒体,hls

所谓流媒体是指采用流式传输的方式在Internet播放的媒体格式。流媒体又叫流式媒体&#xff0c;它是指商家用一个视频传送服务器把节目当成数据包发出&#xff0c;传送到网络上。用户通过解压设备对这些数据进行解压后&#xff0c;节目就会像发送前那样显示出来。流媒体&#xf…

uniapp实现页面左右滑动,上下滑动事件

实现代码&#xff1a; <view class"" touchstart"touchstart" touchend"touchend"> </view> data() {return {touchData: {}, //滑动事件数据} } methods: {touchstart(e) {this.touchData.clientX e.changedTouches[0].clientX;…

android逆向分析概述_Android存储概述

android逆向分析概述Storage is this thing we are all aware of, but always take for granted. Not long ago, every leap in storage capacity was incremental and appeared to be impossible. Nowadays, we don’t give a second thought when contemplating how much of …

小程序地图的使用笔记

这两天在看小程序的地图&#xff0c;写写笔记记录一下 小程序官方文档提供的方法 https://mp.weixin.qq.com/debug/wxadoc/dev/api/location.html 腾讯地图提供的jssdk http://lbs.qq.com/qqmap_wx_jssdk/qqmapwx.html 根据提示使用腾讯地图jssdk需要申请&#xff0c;在实例化的…

JS 实现可停顿的垂直滚动

1 var ScrollMiddle {2 Odiv:document.getElementById(comment), // 目标DOM 3 Oli: document.getElementById(comment).getElementsByTagName(li), 4 times:30, // 配置滚动时间 …