canvas基本动画--微信小程序

如果看了我说的方法还没有做出来的,滴滴我,我给你发js代码。学习勤奋的精神!!!

canvas动画

一、动画效果

1.图片:

在这里插入图片描述

2.页面代码设置
 <view class="uni-padding-wrap uni-common-mt">	
   <view class="animation-element-wrapper">
    <view class="animation-element" :animation="animationData"></view>
	<view class="animation-image" :animation="animationData"></view>
   </view>
   <scroll-view class="animation-buttons" scroll-y="true">
    <button class="animation-button" bindtap="rotate">旋转</button>
    <button class="animation-button" bindtap="scale">缩放</button>
    <button class="animation-button" bindtap="translate">移动</button>
    <button class="animation-button" bindtap="skew">倾斜</button>
    <button class="animation-button" bindtap="rotateAndScale">旋转并缩放</button>
    <button class="animation-button" bindtap="rotateThenScale">旋转后缩放</button>
    <button class="animation-button" bindtap="all">同时展⽰全部</button>
    <button class="animation-button" bindtap="allInQueue">顺序展⽰全部</button>
    <button class="animation-button animation-button-reset" bindtap="reset">还原</button>
   </scroll-view>
  </view>
 </view>
//样式
style:
.animation-element-wrapper {
  display: flex;
  width: 100%;
  padding-top: 150rpx;
  padding-bottom: 150rpx;
  justify-content: center;
  overflow: hidden;
  background-color: #ffffff;
}
.animation-element {
  width: 200rpx;
  height: 200rpx;
  background-color: #1AAD19;
}
.animation-image{
	 width: 200rpx;
	 height: 200rpx;
	 background-color: #ff5500;
}
.animation-buttons {
  padding:30rpx 0;
  width: 100%;
  height: 360rpx;
}
.animation-button {
  float: left;
  line-height: 2;
  width: 44%;
  margin: 15rpx 3%;
}
.animation-button-reset {
  width: 94%;
}

二、动画逻辑

1.wxml页面绑定动画效果:

animation=“{{animationData}}”

2.js文件的逻辑
  1. 设置空集合收集点击的动画数据

data: {
animationData: {}
},

  1. 创建animation实例

var animation = wx.createAnimation({
duration: 1000,
timingFunction: ‘ease’,
})

  1. 调用实例的方法来描述动画

this.animation.rotate(45).scale(2, 2).step()

  1. 通过动画实例的 export 方法导出动画数据传递给组件的 animation 属性

this.setData({
animationData: this.animation.export()
})

3.动画例子
  1. 移动例子
绑定事件:不管是旋转还是移动,还是倾斜等;方法都是下面这种写法,但是动画描述的计算,这个自己得去找,或者直接计算。
translate: function () {
//描述动画
    this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
   //导出动画数据传递给组件的 animation 属性
    this.setData({
      animationData: this.animation.export()
    })
   },

三、关键技术

1. 动画实例(animation)的创建;
2. 导入动画的数据;
3. 点击事件的处理;
4. wxml页面的处理;
5. wxss样式的处理;
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

半粒糖₩

对自己有帮助的,在相应文章回复

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

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

打赏作者

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

抵扣说明:

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

余额充值