微信小程序开发——动画效果

WeChat小程序交流(QQ群:769977169

动画效果的实现,使用wx.createAnimation实现。具体实现时,首先,创建动画对象,并设置相关的参数;其次,设置动画类型,并执行动画;第三,导出并设置动画数据;最后,将设置的动画数据动态配置相应的组件,以此实现组件的动画效果。

效果图


代码示例

xxx.wxml

<view style='width:60px;height:60px;background-color:yellow;' animation="{{moveData}}" bindtap='moveClick'>移动</view>

<view style='width:60px;height:60px;background-color:red;' animation="{{rotateData}}" bindtap='rotateClick'>旋转</view>

<view style='width:60px;height:60px;background-color:green;' animation="{{alphaData}}" bindtap='alphaClick'>透明度</view>

<view style='width:60px;height:60px;background-color:orange;' animation="{{scaleData}}" bindtap='scaleClick'>缩放</view>

<view style='width:60px;height:60px;background-color:blue;' animation="{{skewData}}" bindtap='skewClick'>倾斜</view>

<view style='width:60px;height:60px;background-color:black;color:white' animation="{{matrixData}}" bindtap='matrixClick'>变形</view>

<view style='width:60px;height:60px;background-color:yellow;' animation="{{queueData}}" bindtap='queueClick'>移动\n变小\n透明</view>

www.wxjs

Page({

  /**
   * 页面的初始数据
   */
  data: {
    widthScreen:null,
    moveData:null,
    rotateData:null,
    alphaData:null,
    scaleData:null,
    skewData:null,
    matrixData:null
  },

  moveClick: function(){
    var animation = wx.createAnimation({
      duration: 3000,
      delay: 0,
      timingFunction: "ease",
    });
    
    animation.translate((this.data.widthScreen - 60), 0).step({duration: 3000})
    this.setData({moveData: animation.export()})
  },

  rotateClick: function(even) {
    var animation = wx.createAnimation({})
    animation.rotate(180).step({duration:3000})
    this.setData({rotateData: animation.export()})
  },

  alphaClick: function(even) {
    var animation = wx.createAnimation({})
    animation.opacity(0.1).step({duration: 2000})
    this.setData({alphaData: animation.export()})
  },
  
  scaleClick: function(even) {
    var animation = wx.createAnimation({})
    animation.scale(1.6).step({duration: 2000})
    this.setData({scaleData: animation.export()})
  },
  
  skewClick: function(even) {
    var animation = wx.createAnimation({})
    animation.skew(160).step({duration: 2000})
    this.setData({skewData: animation.export()})
  },
  
  matrixClick: function(even) {
    var animation = wx.createAnimation({})
    animation.matrix(1,3,4,5,2,2).step({ duration: 2000 })
    this.setData({ matrixData: animation.export() })
  },
  
  queueClick: function() {
    var animation = wx.createAnimation({});
    animation.translate((this.data.widthScreen - 60), 0).scale(0.3).opacity(0.5).step({duration: 3000})
    this.setData({queueData: animation.export() })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // 获取屏蔽宽
    var thisBlock = this;
    wx.getSystemInfo({
      success: function(res) {
        thisBlock.setData({
          widthScreen: res.screenWidth
        })
      },
    })
  }
}


  • 11
    点赞
  • 75
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

番薯大佬

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值