微信小程序开发--3.2点击按钮动画

文章展示了如何在小程序中使用colorui库来实现点击加号按钮和购物车标识的动画效果。通过WXML定义元素,WXSS设置样式,以及JavaScript处理点击事件和动画状态的切换,实现了按钮的淡入淡出以及购物车数量标签的缩放效果。
摘要由CSDN通过智能技术生成

效果

1.点击加号按钮动画效果

2.下方购物车标识动画效果

首先导入小程序原生组件库colorui

wxml

//加号按钮
<image catchtap="addToShopCart"  aria-disabled="false" class="animation-{{item.id==clickId?'fade':''}}  basis-sm shadow" data-id="{{item.id}}" src="/static/icons-xiangle/page-serviceShop/addCart.png" style="width:36rpx;height:50rpx;">
</image>

//购物车标识
<view class="cuIcon-cu-image" style="z-index:10;position:fixed;bottom:40rpx;right:0;width:126rpx;height:auto;">
    <image src="/static/icons-xiangle/homepage/bubble-cart.png" style="width:126rpx;height:102rpx;" bindtap="toGoodShopCart"></image>
    <view class="cu-tag badge animation-{{animation}}  basis-sm shadow" style="right:10rpx;background-color:#949FE3;" aria-disabled="false">{{selectedShopAmount}}</view>
</view>

wxss

@import "/colorui/animation.wxss";

js

addToShopCart(e){
      console.log(e);
      var clickId=e.currentTarget.dataset.id
      var animation='scale-down'
      var that = this;
      that.setData({
        animation: animation,
        clickId:clickId
      })
      setTimeout(function() {
        that.setData({
          animation: '',
          clickId:''
        })
      }, 1000)
  }, 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值