js

let animationShowHeight = 300;
Page({
  /**
   * 页面的初始数据
   */
  data: {
    animation: ''
  },
  // 下来
  btnClick: function () {
    var animation = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 1000,
      timingFunction: "ease",
      delay: 0
    })
    this.animation = animation
    animation.translateY(animationShowHeight).step()
    this.setData({
      animation: animation.export(),
    })
  },
  // 上去
  btnClickTo: function () {
    var animation = wx.createAnimation({
      transformOrigin: "50% 50%",
      duration: 1000,
      timingFunction: "ease",
      delay: 0
    })
    this.animation = animation
    animation.translateY(0).step()
    this.setData({
      animation: animation.export(),
    })
  }  
})

wxml

<button type="primary" bindtap="btnClick"> 点我下去 </button>
<button type="primary" bindtap="btnClickTo"> 点我回去 </button>
<view class="body-view" animation="{{animation}}">
  <view>我一会就出来吓死你</view>
  <view>我一会就出来吓死你</view>
  <view>我一会就出来吓死你</view>
</view>

4 Comments

  1. 大佬 默认隐藏,展开显示的呢?就和jq slidedoen slideup效果一样的

发表评论

电子邮件地址不会被公开。 必填项已用*标注