当前位置: 首页 > news >正文

wepy微信小程序自定义底部弹出框功能,显示与隐藏效果(淡入淡出,滑入滑出)

 视图html部分

  <view class="salePz">

 <view class="btnSelPz" @tap="pzModelClick">去选择</view>

  <!-- modal -->
 <view class="modal modal-bottom-dialog" hidden="{{hideFlag}}">
 <view class="modal-cancel" bindtap="hideModal"></view>
 <view class="bottom-dialog-body bottom-positon" animation="{{animationData}}">
  <!-- -->
  <view class='Mselect'>
  <view wx:for="{{optionList}}" wx:key="unique" data-value='{{item}}' bindtap='getOption'>
   {{item}}
  </view>
  </view>
  <view></view>
  <view class='Mcancel' bindtap='mCancel'>
  <text>取消</text>
  </view>
 </view>
 </view>

 </view>

style样式 

<style lang="less">

.btnSelPz{
  width: 150rpx;
  height: 60rpx;
    display: flex;
  justify-content: center;
  align-items: center;
  background: #2a67ea;
  border-radius: 10rpx;
  color: white;
margin-left: 10rpx;
}

// 底部弹出框-------------------------------------------
.arrow{
 display:inline-block;
 border:6px solid transparent;
 border-top-color:#000;
 margin-left:8px;
 position:relative;
 top:6rpx;
}
/* ---------------------------- */
/*模态框*/
.modal{position:fixed; top:0; right:0; bottom:0; left:0; z-index:1000;}
.modal-cancel{position:absolute; z-index:2000; top:0; right:0; bottom: 0; left:0; background:rgba(0,0,0,0.3);}
.bottom-dialog-body{width:100%; position:absolute; z-index:3000; bottom:0; left:0;background:#dfdede;}
/*动画前初始位置*/
.bottom-positon{-webkit-transform:translateY(100%);transform:translateY(100%);}


/* 底部弹出框 */
.bottom-positon{
 text-align: center;
}
.Mselect{
 margin-bottom: 20rpx;
}
.Mselect view{
 padding: 26rpx 0;
 background: #fff;
}
.Mselect view:not(:last-of-type){
 border-bottom: 1px solid #dfdede;
}
.Mcancel{
 background: #fff;
 padding: 26rpx 0;
}
</style>

 js部分

 export default class Web extends wepy.page {
    data = {
   //弹出框
      optionList:['所有','选项1','选项2'],
      value:'所有',
      hideFlag: true,//true-隐藏 false-显示
      animationData: {},//
  }
 }


     // 显示遮罩层
      showModal () {
      this.hideFlag=false
      // 创建动画实例
      var animation = wx.createAnimation({
        duration: 400,//动画的持续时间
        timingFunction: 'ease',//动画的效果 默认值是linear->匀速,ease->动画以低速开始,然后加快,在结束前变慢
      })
      this.animation = animation; //将animation变量赋值给当前动画
      var that=this
      var time1 = setTimeout(function () {
        that.slideIn();//调用动画--滑入
        //  var that = this;
        clearTimeout(time1);
        time1 = null;
      }, 100)
          this.$apply()
      }

      // 隐藏遮罩层
      hideModal () {
      var animation = wx.createAnimation({
        duration: 400,//动画的持续时间 默认400ms
        timingFunction: 'ease',//动画的效果 默认值是linear
      })
      this.animation = animation
      this.slideDown();//调用动画--滑出
      var that=this
      var time1 = setTimeout(function () {
        that.hideFlag=true
         that.$apply()
        clearTimeout(time1);
        time1 = null;
      }, 220)//先执行下滑动画,再隐藏模块
          this.$apply()
      }
          //动画 -- 滑入
      slideIn (){
      this.animation.translateY(0).step() // 在y轴偏移,然后用step()完成一个动画
        this.animationData=this.animation.export()
          this.$apply()
      }
      //动画 -- 滑出
      slideDown(){
      this.animation.translateY(300).step()
        this.animationData= this.animation.export()
          this.$apply()
      }

    methods = {
      // 点击选项
    getOption(e){
      this.value=e.currentTarget.dataset.value
      this.hideFlag=true
      this.$apply()
    },
    //取消
    mCancel() {
    this.hideModal();
        this.$apply()
    },


 methods = {
      // 点击选项
    getOption(e){
      this.value=e.currentTarget.dataset.value
      this.hideFlag=true
      this.$apply()
    },
    //取消
    mCancel() {
    this.hideModal();
        this.$apply()
    },

}

Tips: 

相关文章:

  • 【sql靶场】第11、12关-post提交注入
  • 《突破GitHub网路访问困境:揭秘与应对》
  • 基于大模型的上睑下垂手术全流程预测与方案优化研究报告
  • K8S学习之基础三十:k8s的资源访问方式
  • 博通免费版(winlinux) VMware Workstation Pro 17 安装包分享
  • ORACLE 19.8版本遭遇ORA-600 [kqrHashTableRemove: X lock].宕机的问题分析
  • [C语言笔记]08、函数
  • 云服务器新手配置内网穿透服务(frp)
  • Java 方法引用(Method Reference)从入门到精通
  • 工作记录 2017-01-12
  • vue3 + css 列表无限循环滚动+鼠标移入停止滚动+移出继续滚动
  • 开源:LMDB 操作工具:lmcmd
  • 【万字总结】构建现代Web应用的全方位性能优化体系学习指南(一)
  • 基于Hadoop的城市道路交通数据的可视化分析-Flask
  • SAP ABAP BDC 录屏开发
  • spring boot实现程序运行过程中数据源动态切换
  • STM32配套程序接线图
  • WPF程序使用AutoUpdate实现自动更新
  • 重学vue3(二):vue3生命周期(包含父与子)
  • 专家系统如何运用谓词逻辑进行更复杂的推理
  • 预付网站建设费用会计分录/seo工作内容
  • 找柳市做网站/精准客户运营推广
  • 餐饮团购网站建设/广州百度seo
  • 在线代理访问/向日葵seo
  • 广州网站备案方案/百度爱采购排名
  • 网站建设费能算作无形资产吗/谷歌官网注册入口