ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

微信小程序开发之——CSS动画

2022-01-13 09:58:00  阅读:264  来源: 互联网

标签:box 动画 rotate 微信 程序开发 background animationData font CSS


一 概述

上一节介绍了通过CSS属性keyframes设置图片选择动画,本文介绍以下两种形式的动画:

  • this.animate 接口(旧的)
  • wx.createAnimation接口(新的,2.9.0开始支持)

二 this.animate

2.1 布局文件

<view class="container">
  <view class="box">
    <!--this.animate-->
    <image id="loading" src="/images/icon_loading.png"></image>
    <text>加载中...</text>
  </view>
</view>

2.2 样式文件

page {
  background: gray;
}

.box {
  width: 400rpx;
  height: 300rpx;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border-radius: 30rpx;
}

.box image {
  width: 100rpx;
  height: 100rpx;
}

.box text {
  margin-top: 20rpx;
  font-size: large;
  font-weight: bold;

}

2.3 逻辑文件

onShow: function () {
    this.animate('#loading', [
      { opacity: 1.0, rotate: 0},
      { opacity: 1.0, rotate: 45 },
      { opacity: 1.0, rotate: 90 },
      { opacity: 1.0, rotate: 360 },
    ], 5000)
  },

2.4 效果图

2.5 说明

  • this.animate动画在开发者工具中有时候不执行动画
  • 此种动画在真机上演示

三 wx.createAnimation动画

3.1 布局文件

<view class="container">
  <view class="box">
    <image id="loading" src="/images/icon_loading.png" animation="{{animationData}}"></image>
    <text>加载中...</text>
  </view>
</view>

3.2 样式文件(同上)

page {
  background: gray;
}

.box {
  width: 400rpx;
  height: 300rpx;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  border-radius: 30rpx;
}

.box image {
  width: 100rpx;
  height: 100rpx;
}

.box text {
  margin-top: 20rpx;
  font-size: large;
  font-weight: bold;

}

3.3 逻辑文件

 data: {
    animationData: ''
  },
 onShow: function () {
    var anim = wx.createAnimation({
      duration: 5000,
      timingFunction: "linear"
    })
    this.animationData = anim;
    anim.rotate(180).step();
    this.setData({
      animationData: anim.export()
    })
  },  

3.4 效果图

四 参考

标签:box,动画,rotate,微信,程序开发,background,animationData,font,CSS
来源: https://blog.csdn.net/Calvin_zhou/article/details/122467556

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有