微信小程序animation API详解及实例代码分享

高洛峰
Libérer: 2017-03-13 10:33:16
original
2147 Les gens l'ont consulté

这篇文章主要介绍了微信小程序animation API详解及实例代码分享的相关资料,需要的朋友可以参考下

动画水还是比较深的,这里只是简单介绍下小程序中动画的一些属性和注意事项,做动画前一定要整理好思路将动画一步步分解,再进行组合!这里只做引入。

wx.createAnimation(object)

看官方介绍

1.创建一个动画实例animation。调用实例的方法来描述动画。最后通过动画实例的export方法导出动画数据传递给组件的animation属性。

2.调用动画操作方法后要调用 step() 来表示一组动画完成,可以在一组动画中调用任意多个动画方法,一组动画中的所有动画会同时开始,一组动画完成后才会进行下一组动画。step 可以传入一个跟 wx.createAnimation() 一样的配置参数用于指定当前组动画的属性

这还是比较好理解的比如第一条对应代码animation: this.animation.export()
第二条比如缩放动画,也就说是一组scale,scaleX, scaleY…为一缩放动画组的一个动画方法,缩放动画组和旋转动画组通过step()链接,按顺序执行。代码中体验吧!看效果反过来看会更容易理解

主要属性:

微信小程序animation API详解及实例代码分享

这里主要树下timingFunction和transformOrigin

timingFunction 设置动画效果

  1. linear 默认为linear 动画一直较为均匀

  2. ease 开始时缓慢中间加速到快结束时减速

  3. ease-in 开始的时候缓慢

  4. ease-in-out 开始和结束时减速

  5. ease-out 结束时减速

  6. step-start 动画一开始就跳到 100% 直到动画持续时间结束 一闪而过

  7. step-end 保持 0% 的样式直到动画持续时间结束 一闪而过

transformOrigin 设置动画的基点 默认%50 %50 0

left,center right是水平方向取值,对应的百分值为left=0%;center=50%;right=100%

top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%

动画组及动画方法

样式:

微信小程序animation API详解及实例代码分享

旋转:

微信小程序animation API详解及实例代码分享

缩放:

微信小程序animation API详解及实例代码分享

偏移:

微信小程序animation API详解及实例代码分享

倾斜:

微信小程序animation API详解及实例代码分享

矩阵变形:

微信小程序animation API详解及实例代码分享

演示单个动画组效果

微信小程序animation API详解及实例代码分享

wxml


<view class="container">
 <view animation="{{animation}}" class="view">我在做动画</view>
</view>
<button type="primary" bindtap="rotate">旋转</button>
Copier après la connexion

js


Page({
 data:{
  text:"Page animation",
  animation: &#39;&#39;
 },
 onLoad:function(options){
  // 页面初始化 options为页面跳转所带来的参数
 },
 onReady:function(){
  // 页面渲染完成
  //实例化一个动画
  this.animation = wx.createAnimation({
   // 动画持续时间,单位ms,默认值 400
   duration: 1000, 
   /**
    * http://www.php.cn/,0,.58,1 
    * linear 动画一直较为均匀
    * ease  从匀速到加速在到匀速
    * ease-in 缓慢到匀速
    * ease-in-out 从缓慢到匀速再到缓慢
    * 
    * http://www.php.cn/
    * step-start 动画一开始就跳到 100% 直到动画持续时间结束 一闪而过
    * step-end  保持 0% 的样式直到动画持续时间结束    一闪而过
    */
   timingFunction: &#39;linear&#39;,
   // 延迟多长时间开始
   delay: 100,
   /**
    * 以什么为基点做动画 效果自己演示
    * left,center right是水平方向取值,对应的百分值为left=0%;center=50%;right=100%
    * top center bottom是垂直方向的取值,其中top=0%;center=50%;bottom=100%
    */
   transformOrigin: &#39;left top 0&#39;,
   success: function(res) {
    console.log(res)
   }
  })
 },

 /**
  * 旋转
  */
 rotate: function() {
  //顺时针旋转10度
  //
  this.animation.rotate(150).step()
  this.setData({
   //输出动画
   animation: this.animation.export()
  })
 },

 onShow:function(){
  // 页面显示
 },
 onHide:function(){
  // 页面隐藏
 },
 onUnload:function(){
  // 页面关闭
 }
})
Copier après la connexion

演示多个动画组效果

微信小程序animation API详解及实例代码分享

这里我们只需要更改以下代码即可

  /**
   * 旋转
   */
  rotate: function() {
    //两个动画组 一定要以step()结尾
    /**
     * 动画顺序 顺时针旋转150度>x,y 放大二倍>x,y平移10px>x,y顺时针倾斜>改变样式和设置宽度宽度
     */
    this.animation.rotate(150).step().scale(2).step().translate(10).step().skew(10).step().opacity(0.5).width(10).step({ducation: 8000})
    this.setData({
      //输出动画
      animation: this.animation.export()
    })
  }

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!