2021-09-24 微信小程序 翻牌动画

本文介绍了如何在微信小程序中实现翻牌动画效果。通过结构样式和动画控制,正面和背面的图片能够实现翻转展示。关键代码包括使用`wx.createAnimation`创建动画对象,设置动画参数如旋转角度和延迟时间,以及利用`bindtap`事件处理翻转后的关闭操作。文章详细阐述了动画的实现过程,为小程序开发者提供了参考。
摘要由CSDN通过智能技术生成

微信小程序 翻牌动画

效果

在这里插入图片描述

结构

 <view class='main' style='display:{{cardDisplay}}' bindtap="closeCardDisplayFuc">
        <view class="" wx:if="{{showImg}}">
            <!-- 正面的框 -->
            <view class="box b1" animation="{{animationMain}}" data-id="1">
                <image src="{{src1}}"></image>
            </view>
            <!-- 背面的框 -->
            <view class="box b2" animation="{{animationBack}}" data-id="2">
                <image src="{{src2}}"></image>
            </view>
            <view class="close" bindtap="closeCardDisplayFuc"></view>
        </view>
    </view>

样式

 //   抽卡  动画
    .main {
        display: none;
        position: fixed;
        top: 0%;
        left: 0%;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.7);
        z-index: 1001;

        /* transform: translate(-50%,-50%); */
        /* //子元素获得透视效果  */
        -webkit-perspective: 1500;
        -moz-perspective: 1500;
    }

    .box {
        position: absolute;
        top: 174rpx;
        left: 0rpx;
        width: 750rpx;
        height: 985rpx;
        transition: all 1s;
        backface-visibility: hidden;
        // border-radius: 10px;
        cursor: pointer;
        z-index: 10002;
    }

    .box image {
        // border-radius: 10px;
        width: 100%;
        height: 100%;
    }

    .b1 {
        /* background:skyblue; */
        opacity: 0.9;   
        transform: scale(0, 0);  //默认隐藏
    }


    .b2 {
        /* background:tomato; */
        transform: rotateY(-180deg);
    }

动画

  /**
* 卡片翻转
*/
  rotateFn: async function (e) {
          this.setData({
        animationMain: null,
        animationBack: null,
        showImg: false
      })
       setTimeout(function () {
            that.setData({
              cardDisplay: "block",
              showImg: true,
              src1: 'https://static.sprucesmart.com/cardCollecting/bac.png ',
         src2:'https://static.sprucesmart.com/cardCollecting/card_huan.png',
            })
            setTimeout(() => {
              var id = e.currentTarget.dataset.id
              that.animation_main = wx.createAnimation({
                duration: 600,
                timingFunction: 'linear',
              })
              that.animation_back = wx.createAnimation({
                duration: 600,
                timingFunction: 'linear',
                delay: 600
              })
              //背面图展示  并旋转180度
              that.animation_main.scale(1, 1).step().rotateY(180).step()
              //正面图旋转展示
              that.animation_back.rotateY(0).step()
              that.setData({
                animationMain: that.animation_main.export(),
                animationBack: that.animation_back.export(),
              })
            }, 500);
          }, 800);
     },
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值