小程序animation动画效果(小程序组件案例)

WXML

<view class="container">
  <view class="page-body">
    <view class="page-section">

      <view class="animation-element-wrapper">
        <view class="animation-element" animation="{{animation}}"></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>
</view>

WXSS:

.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-buttons {
  padding: 30rpx 50rpx 10rpx;
  width: 100%;
  height: 600rpx;
  box-sizing: border-box;
}
.animation-button {
  float: left;
  line-height: 2;
  width: 300rpx;
  margin: 15rpx 12rpx;
}

.animation-button-reset {
  width: 620rpx;
}

JS:

Page({
  onReady: function () {
    this.animation = wx.createAnimation()
  },
  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)
      .scale(Math.random() * 2)
      .step()
    this.setData({ animation: this.animation.export() })
  },
  rotateThenScale: function () {
    this.animation.rotate(Math.random() * 720 - 360).step()
      .scale(Math.random() * 2).step()
    this.setData({ animation: this.animation.export() })
  },
  all: function () {
    this.animation.rotate(Math.random() * 720 - 360)
      .scale(Math.random() * 2)
      .translate(Math.random() * 100 - 50, Math.random() * 100 - 50)
      .skew(Math.random() * 90, Math.random() * 90)
      .step()
    this.setData({ animation: this.animation.export() })
  },
  allInQueue: function () {
    this.animation.rotate(Math.random() * 720 - 360).step()
      .scale(Math.random() * 2).step()
      .translate(Math.random() * 100 - 50, Math.random() * 100 - 50).step()
      .skew(Math.random() * 90, Math.random() * 90).step()
    this.setData({ animation: this.animation.export() })
  },
  reset: function () {
    this.animation.rotate(0, 0)
      .scale(1)
      .translate(0, 0)
      .skew(0, 0)
      .step({ duration: 0 })
    this.setData({ animation: this.animation.export() })
  }
})

 

转载于:https://www.cnblogs.com/yiweiyihang/p/7117487.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我无法提供完整的微信小程序50个api和组件用法及案例代码。但是,我可以给你提供一些常用的微信小程序api和组件及其简单用法: 1. wx.request() - 发起网络请求 ``` wx.request({ url: 'url', data: {}, header: {}, method: 'GET/POST/PUT/DELETE', dataType: 'json', responseType: 'text', success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) ``` 2. wx.navigateTo() - 跳转到页面 ``` wx.navigateTo({ url: 'url' }) ``` 3. wx.showLoading() - 显示加载提示框 ``` wx.showLoading({ title: 'loading', mask: true, }) ``` 4. wx.hideLoading() - 隐藏加载提示框 ``` wx.hideLoading() ``` 5. wx.showToast() - 显示消息提示框 ``` wx.showToast({ title: 'message', icon: 'success/warning/none', duration: 2000, }) ``` 6. wx.showModal() - 显示模态框 ``` wx.showModal({ title: 'title', content: 'content', showCancel: true, cancelText: 'cancel', confirmText: 'confirm', success: function(res) {}, fail: function(res) {}, complete: function(res) {}, }) ``` 7. wx.getStorageSync() - 同步获取本地数据缓存 ``` wx.getStorageSync('key') ``` 8. wx.setStorageSync() - 同步设置本地数据缓存 ``` wx.setStorageSync('key', 'value') ``` 9. wx.createAnimation() - 创建动画实例 ``` var animation = wx.createAnimation({ duration: 1000, timingFunction: 'ease', delay: 0, transformOrigin: '50% 50% 0', }) ``` 10. wx.createCanvasContext() - 创建画布上下文 ``` var context = wx.createCanvasContext('canvas') ``` 以上是一些常用的微信小程序api和组件及其简单用法,希望对你有所帮助。如果需要更详细的内容和案例代码,建议你去官方文档查阅。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值