zoukankan      html  css  js  c++  java
  • 微信小程序——实现动画循环播放

    今天在做砍价页面的时候需要将一个按钮动起来,效果图如下:

    其实它实现的原理很简单,就是循环的缩小放大。

    css3中的animate 有个属性是 animation-iteration-count 可以控制动画的循环播放,但是小程序里面没有。该怎么实现呢?

    无非就是2种状态的切换。

    wxml:

    <button class='cut-btn' open-type='share' animation="{{animationData}}">喊好友砍一刀</button>

    js:

    Page({
    
      /**
       * 页面的初始数据
       */
      data: {
        animationData: {}
      },
      
      /**
       * 生命周期函数--监听页面显示
       */
      onShow: function () {
        var animation = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease',
        })
        this.animation = animation
        var next = true;
        //连续动画关键步骤
        setInterval(function () {
          if (next) {
            this.animation.scale(0.95).step()   
            next = !next;
          } else {
            this.animation.scale(1).step()
            next = !next;
          }
          this.setData({
            animationData: animation.export()
          })
        }.bind(this), 500)
      },
    
      
    
      /**
       * 用户点击右上角分享
       */
      onShareAppMessage: function () {
      
      }
    })

    上述代码即可实现动画循环播放的效果了~~

  • 相关阅读:
    Swoole 协程使用示例及协程优先级
    Swoole 协程简介
    Laravel Redis分布式锁的使用
    Laravel Redis分布式锁实现源码分析
    Swoole 中使用异步任务
    runtime相关面试
    oc笔试题
    属性关键字面试题
    KVC面试题
    KVO面试题
  • 原文地址:https://www.cnblogs.com/sese/p/9296091.html
Copyright © 2011-2022 走看看