小程序wepy踩坑之旅(四)----- 简单的动画

大家可以先看下官网小程序apianimation:https://developers.weixin.qq.com/miniprogram/dev/api/api-animation.html,看完之后推荐看一下http://www.jb51.net/article/102263.htm讲animation的文章,上面写的很详细

这里写图片描述

源码如下:(直接复制到一个wepy文件中就可以使用了)

<template>
  <view class="shop-cart">
    <button class="show-btn" @tap="show">展示</button>
    <view class="demo" animation="{{animationData}}">
      <button class="btn" @tap="hide">X</button>
    </view>
  </view>
</template>

<script>
import wepy from 'wepy'

export default class ShopCart extends wepy.page {
  config = {
    navigationBarTitleText: '购物车'
  };
  components = {
  };

  mixins = [];

  data = {
    animationData: {}
  }

  computed = {}

  methods = {
    show () {
      this.animation.height('200rpx').step()
      this.setData({
        animationData: this.animation.export()
      })
    },
    hide() {
      this.animation.height(0).step()
      this.setData({
        animationData: this.animation.export()
      })
    }
  }

  events = {}
  onLoad() {
    let animation = wx.createAnimation({
      duration: 1000,
      timingFunction: 'ease'
    })
    this.animation = animation

  }
}
</script>
<style lang="less">
  .demo {
    width: 100%;
    height: 0rpx;
    background: pink;
    position: absolute;
    bottom: 0;
    .btn { width: 30rpx;
      height: 30rpx;
      color: #000;
      font-size: 10rpx;
      position: absolute;
      top: 0;
      right: 0;
    }
  }
</style>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值