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

微信小程序-动画

文章目录

  • 微信小程序-动画
    • 概述
    • 使用

微信小程序-动画

概述

通过调用 wx.createAnimation() 方法创建 Animation 实例。

let animation = wx.createAnimation(Object)

再通过调用 Animation 的各方法实现动画效果。

wx.createAnimation()方法:

选项类型说明
durationnumber动画持续事件,单位为毫秒,默认值为 400
timingFunctionstring动画的效果,默认值为 linear
delaynumber动画延迟执行的事件,单位为毫秒,默认值为 0
transformOriginstring设置旋转元素的基点位置,默认值为 50% 50% 0,这3个值分别表示 x轴、y轴、z轴

timingFunction合法值:

合法值说明
linear动画全程线性速度
ease动画先低速开始,然后加快,在结束前变慢
ease-in动画以低速开始
ease-in-out动画以低速开始和结束
ease-out动画以低速结束
step-start动画第一帧就跳至结束状态知道结束
step-end动画一直保持开始状态,最后一帧跳到结束状态

Animation方法:

方法说明
rotate(number angle)旋转。从原点顺时针旋转一个角度,角度取值范围为 [-180,180]
export()导出动画队列。export() 方法每次调用后会清掉之前的动画操作
scale(number sx, number sy)缩放。当仅有 sx 参数时,表示在 X 轴、Y 轴同时缩放sx倍数,在 Y 轴缩放 sy 倍数
translate(number tx, number ty)平移。当仅有该参数时表示在 X 轴偏移 tx,单位 px,在 Y 轴平移的距离,单位为 px
skew(number ax, number ay)倾斜。对 X 轴坐标倾斜的角度,范围 [-180, 180],对 Y 轴坐标倾斜的角度,范围 [-180, 180]
step(Object object)表示一组动画完成。可以在一组动画中调用任意多个动画方法,一组动画中的所有动画会同时开始,一组动画完成后才会进行下一组动画。
opacity(number value)设置透明度,范围为 0~1
backgroundColor(string value)设置背景色
width(number|string value)设置宽度
top(number|string value)设置 top 值

使用

<view class="anim-pic">
  <image src="/images/img.png" animation="{{animation}}" />
</view>
<view class="anim-btns">
  <button bind:tap="rotate">旋转</button>
  <button bind:tap="scale">缩放</button>
  <button bind:tap="translate">移动</button>
  <button bind:tap="skew">倾斜</button>
  <button bind:tap="rotateAndScale">同时旋转和缩放</button>
  <button bind:tap="rotateThenScale">先旋转后缩放</button>
  <button bind:tap="all">同时展示全部</button>
  <button bind:tap="allOrder">按顺序展示全部</button>
  <button class="reset" bind:tap="reset">重置</button>
</view>
Page({
  data: {
    animation: {}
  },
  /** 旋转 */
  rotate: function () {
    this.animation.rotate(Math.random() * 720 - 360).step()
    this.setData({
      animation: this.animation.export()
    })
  },
  /** 缩放 */
  scale: function () {
    this.animation.scale(Math.random() * 2).step()
    this.setData({
      animation: this.animation.export()
    })
  },
  /** 平移 */
  translate: function () {
    this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
    this.setData({
      animation: this.animation.export()
    })
  },
  /** 倾斜 */
  skew: function () {
    this.animation.skew(Math.random() * 90, Math.random() * 90).step()
    this.setData({
      animation: this.animation.export()
    })
  },
  /** 同时旋转和缩放 */
  rotateAndScale: function () {
    this.animation.rotate(Math.random() * 720 - 360)
    this.animation.scale(Math.random() * 2).step()
    this.setData({
      animation: this.animation.export()
    })
  },
  /** 先选择后缩放 */
  rotateThenScale: function () {
    this.animation.rotate(Math.random() * 720 - 360).step()
    this.animation.scale(Math.random() * 2).step()
    this.setData({
      animation: this.animation.export()
    })
  },
  /** 同时旋转、缩放、平移、倾斜 */
  all: function () {
    this.animation.rotate(Math.random() * 720 - 360)
    this.animation.scale(Math.random() * 2)
    this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50)
    this.animation.skew(Math.random() * 90, Math.random() * 90).step()
    this.setData({
      animation: this.animation.export()
    })
  },
  /** 按顺序执行:旋转、缩放、平移、倾斜 */
  allOrder: function () {
    this.animation.rotate(Math.random() * 720 - 360).step()
    this.animation.scale(Math.random() * 2).step()
    this.animation.translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
    this.animation.skew(Math.random() * 90, Math.random() * 90).step()
    this.setData({
      animation: this.animation.export()
    })
  },
  /** 重置 */
  reset: function () {
    this.animation.rotate(0).scale(1).translate(0, 0).skew(0, 0).step({
      duration: 0
    })
    this.setData({
      animation: this.animation.export()
    })
  },
  /
  onReady: function () {
    this.animation = wx.createAnimation({
      duration: 1000,
      timingFunction: "ease"
    })
  }
})

http://www.kler.cn/news/326724.html

相关文章:

  • python爬虫bs4库的用法
  • 【电机-概述及分类】
  • 【SQL】笛卡尔积比较收入更高的员工
  • 如何用Python监控本股市的方法
  • 【中关村在线-注册/登录安全分析报告】
  • 基于单片机的多点温度测量系统
  • 在Ubuntu下通过Docker部署NAS服务器
  • 遇到慢SQL、SQL报错,应如何快速定位问题 | OceanBase优化实践
  • Flet介绍:平替PyQt的好用跨平台Python UI框架
  • sheng的学习笔记-logback
  • 实验OSPF路由协议(课内实验)
  • 运输层和应用层之间的接口和端口有什么关系
  • Android常用C++特性之std::optional
  • 7. 无线网络安全
  • Docker全家桶:Docker Compose项目部署
  • CICD Jenkins实现Pipline
  • sqli-labs时间盲注、布尔盲注脚本
  • 数据结构之链表(2),双向链表
  • 面试系列-携程暑期实习一面
  • C++ | Leetcode C++题解之第438题找到字符串中所有字母异位词
  • Python Web 应用中的 API 网关集成与优化
  • IText导出pdf不显示泰文
  • 438. 找到字符串中所有字母异位词
  • uniapp 知识点
  • 【前端样式】Sweetalert2简单用法
  • 如何使用ssm实现个人日常事务管理系统+vue
  • 金融教育宣传月 | 平安养老险百色中心支公司开展金融知识“消保县域行”宣传活动
  • 心理咨询预约管理系统(含源码+sql+视频导入教程)
  • web前端与koa框架node后端实现分片断点上传
  • xtu oj 六边形