zoukankan      html  css  js  c++  java
  • 微信小程序底部弹窗动画

    第一步,在组件里编写弹窗的代码

    <!-- 活动类型弹框 -->
      <view class='bottomModel' wx:if="{{modelFlag}}" catchtouchmove="toCatch"></view>
      <view class='fixedModel' wx:if="{{modelFlag}}" animation='{{animationData}}'>
        <view class='wraps'>
          <view class='fixedTitle'>
            <view class='commony' bindtap='noShow'>取消</view>
            <view class='centerTitle'>活动类型</view>
            <view class='commony' bindtap='sure'>确定</view>
          </view>
          <view class='fixedContent'>
            <view class='contents' wx:for="{{arr}}"  wx:for-index="idx" wx:key="idx">
              <view class='items' bindtap='chooseItem' id="{{idx}}">
                <image class='icons' wx:if="{{item.checked}}" src='{{choose}}'></image>
                <image class='icons' wx:else src='{{quan}}'></image>
                <view>{{item.classify_name}}</view>
              </view>
            </view>
          </view>
        </view>  
      </view>

    第二部,在对应的点击事件中

    //活动类型
      activityType: function () {
        // 用that取代this,防止不必要的情况发生
        var that = this;
        // 创建一个动画实例
        var animation = wx.createAnimation({
          // 动画持续时间
          duration: 500,
          // 定义动画效果,当前是匀速
          timingFunction: 'linear'
        })
        // 将该变量赋值给当前动画
        that.animation = animation
        // 先在y轴偏移,然后用step()完成一个动画
        animation.translateY(550).step()
        // 用setData改变当前动画
        that.setData({
          // 通过export()方法导出数据
          animationData: animation.export(),
          // 改变view里面的Wx:if
          modelFlag: true
        })
        // 设置setTimeout来改变y轴偏移量,实现有感觉的滑动
        setTimeout(function () {
          animation.translateY(0).step()
          that.setData({
            animationData: animation.export()
          })
        }, 200)
      },

    第三部,隐藏弹框

    noShow: function () {
        var that = this;
        var animation = wx.createAnimation({
          duration: 1000,
          timingFunction: 'linear'
        })
        that.animation = animation
        animation.translateY(550).step()
        that.setData({
          animationData: animation.export()
    
        })
        setTimeout(function () {
          animation.translateY(0).step()
          that.setData({
            animationData: animation.export(),
            modelFlag: false
          })
        }, 200)
      },

    注意:上面的550是你弹框的高度rpx,上面的catchtouchmove是弹框显示的时候防止地图的遮罩层滚动

    toCatch:function(){
        return false;
      },

    效果如下

  • 相关阅读:
    css !import
    算法
    java web 运动前端
    oauth 2
    js 优化
    js 代码优化 (写的可以)
    2015/08/17 《有两条均线,你应该注意》
    佳能相机操作 EDSDK 教程 C# 版本
    2015/8/14——了2000股,是否正确呢——明天待验证?
    系统架构师考试——程序计数器 PC, 指令寄存器IR、状态寄存器SR、通用寄存器GR
  • 原文地址:https://www.cnblogs.com/ldlx-mars/p/10598747.html
Copyright © 2011-2022 走看看