微信小程序点击按钮聚合动画

11 篇文章 0 订阅

微信小程序点击按钮聚合动画
效果如下
在这里插入图片描述

wxml

<view class="allimgs">
    <image src="qst_img/999_1.png" class="img-style" animation="{{animCollect}}" bindtap="collect"></image>
    <image src="qst_img/999.png" class="img-style" animation="{{animTranspond}}" bindtap="transpond"></image>
    <image src="qst_img/6999.png" class="img-style" animation="{{animInput}}" bindtap="input"></image>
		<image src="qst_img/6999.png" class="img-style" animation="{{animInput1}}" bindtap="input"></image>
		<image src="qst_img/6999.png" class="img-style" animation="{{animInput2}}" bindtap="input"></image>
		<image src="qst_img/1999.png" class="img-plus-style"  catchtap="moreBtn"></image>
</view>

wxss


.img-plus-style {
    height: 80rpx;
    width: 80rpx;
    position: fixed;
    bottom: 400rpx;
    right: 5%;
    z-index: 100;
}
 
.img-style {
    height: 80rpx;
    width: 80rpx;
    position: fixed;
    bottom: 400rpx;
    right: 5%;
    opacity: 0;
}

js
js 根据需要展示按钮的数量调整x以及y轴的值即可


    moreBtn: function () {
        this.plus();
      },
      //点击弹出
      plus: function () {
        if (!this.data.isPopping) {
          //弹出
          this.popp();
          this.setData({
            isPopping: true
          })
          }
        else {
       
          //缩回
          this.takeback();
          this.setData({
            isPopping: false
          });
          // console.log("弹出")
        }
      },
      input: function () {
        console.log("input")
      },
      transpond: function () {
        console.log("transpond")
      },
      collect: function () {
       console.log("transpond")
      },
       
      //弹出动画
      popp: function () {
        //plus顺时针旋转
        let animationPlus = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease'
        })
        let animationcollect = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease'
        })
        let animationTranspond = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease'
        })
        let animationInput = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease'
        })
        let animationInput1 = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
          })
          let animationInput2 = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
          })
        // animationPlus.rotateZ(180).step(); // 暂时注释
        animationcollect.translate(-0, -60).rotateZ(0).opacity(1).step();
        animationTranspond.translate(-55, -40).rotateZ(0).opacity(1).step();
        animationInput.translate(-75, 10).rotateZ(0).opacity(1).step();
        animationInput1.translate(-55, 60).rotateZ(0).opacity(1).step();
        animationInput2.translate(-0, 80).rotateZ(0).opacity(1).step();
        this.setData({
          animPlus: animationPlus.export(),
          animCollect: animationcollect.export(),
          animTranspond: animationTranspond.export(),
          animInput: animationInput.export(),
          animInput1:animationInput1.export(),
          animInput2:animationInput2.export(),
        })
      },
      //收回动画
      takeback: function () {
        //plus逆时针旋转
        let animationPlus = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease'
        })
        let animationcollect = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease'
        })
        let animationTranspond = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease'
        })
        let animationInput = wx.createAnimation({
          duration: 500,
          timingFunction: 'ease'
        })
        let animationInput1 = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
          })
          let animationInput2 = wx.createAnimation({
            duration: 500,
            timingFunction: 'ease'
          })
        animationPlus.rotateZ(0).step();
        animationcollect.translate(0, 0).rotateZ(0).opacity(0).step();
        animationTranspond.translate(0, 0).rotateZ(0).opacity(0).step();
        animationInput.translate(0, 0).rotateZ(0).opacity(0).step();
        animationInput1.translate(0, 0).rotateZ(0).opacity(0).step();
        animationInput2.translate(0, 0).rotateZ(0).opacity(0).step();
        this.setData({
          animPlus: animationPlus.export(),
          animCollect: animationcollect.export(),
          animTranspond: animationTranspond.export(),
          animInput: animationInput.export(),
          animInput1: animationInput1.export(),
          animInput2: animationInput2.export(),
        })
      },

希望此文对正在学习进步的你有所帮助 ~一起加油
转载于:https://my.oschina.net/lanyu96/blog/3093995

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值