小程序动画 animation 的常规使用

公司小程序项目比较多,最近正好有时间看一下小程序的动画,同时记录一下我的学习过程;看到这个文章的,我建议你直接去小程序后台:https://developers.weixin.qq.com/miniprogram/dev/api/ui/animation/wx.createAnimation.html

1、使用
// wxml 代码
<view animation="{{move}}">小程序动画</view>

//js
onLoad() {
    this.load()
},
load(){
//初始化
  let move = wx.createAnimation({
    duration:1000, 
    timingFunction:"ease-in-out"
  })
  move.backgroundColor("#ccc").translateY(100).rotate(360).step()
  this.setData({move:move.export()})
},

duration:持续时间
timingFunction:动画效果
delay:延迟时间
transformOrigin:动画原点

2、相关方法

1、backgroundColor() :设置背景色(“red”);
2、bottom():设置 bottom 的值,传入 number 则默认使用 px;
3、left():设置 left 的值;
4、right():设置 right 的值;
5、top():设置 top 的值;
6、width():设置 width 的值;
7、height():设置 height 的值;
8、opacity():设置透明度(0-1);

1、rotate():旋转,选择角度范围 [-180, 180];
2、rotateX():从 X 轴顺时针旋转一个角度;
3、rotateY():从 Y 轴顺时针旋转一个角度;
4、rotateZ():从 Z 轴顺时针旋转一个角度;
5、rotate3d():上面三个的缩写(x,y,z,angle);
6、scale():缩放(x,y);
7、scaleX():X 轴的缩放倍数;
8、scaleY():Y 轴的缩放倍数;
9、scaleZ():Z 轴的缩放倍数;
10、scale3d():上面三个的缩写(x,y,z);
11、transkate():平移;
12、transkateX():在 X 轴平移的距离,单位为 px;
13、transkateY():在 Y轴平移的距离,单位为 px;
14、transkateZ():在 Z 轴平移的距离,单位为 px;
15、transkate3d():上面三个的缩写(x,y,z) [-180, 180];
16、skew():对 X、Y 轴坐标进行倾斜(x,y);
17、skewX():对 X 轴坐标进行倾斜;
18、skewY():对 Y 轴坐标进行倾斜;

1、export():导出动画队列;export 方法每次调用后会清掉之前的动画操作;
2、step():表示一组动画完成。可以在一组动画中调用任意多个动画方法,一组动画中的所有动画会同时开始,一组动画完成后才会进行下一组动画;类似 wx.createAnimation;

matrix 和 matrix3d 可以参考:https://blog.csdn.net/weixin_43867717/article/details/122036846

load(){
    let move = wx.createAnimation({
      duration:1000,
      timingFunction:"ease-in-out"
    })
    move.left(200).scale(1).skew(30,0).step({
      duration:500,
      timingFunction:"ease"
    })
    move.scale(0.7).skew(0,0).step({
      duration:500,
      timingFunction:"ease"
    })
    this.setData({move:move.export()})
  },
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值