微信小程序:自定义弹框

效果图

不说废话,直接上代码 代码片.

.wxml:

   <!-- 自定义弹框-->
    <view class="mask" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>
    <view class="modalDlg" wx:if="{{showModal}}">
    <view style="padding:5%;width:100%;height:100%">
        <view class="title">提示</view>
        <view style="padding:30rpx;word-wrap: break-word;font-size: 30rpx;">
          {{content}}
        </view>
    </view>
    <view   class="modalBtnBox">
      <view class="modalBtnCommon modalBtnL" bindtap="cancel">取消</view>
      <view class="modalBtnCommon modalBtnR" bindtap="enter">{{btnText}}</view>
    </view>
    </view>

.wxss:

/* 自定义弹框 */
.mask{
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: #000;
  z-index: 9000;
  opacity: 0.7;
}

.modalDlg{
  width: 600rpx;
  height: 450rpx;
  position: fixed;
  top:50%;
  left: 50%;
  z-index: 9999;
  transform: translate(-50%,-50%);
  background-color: #fff;
  border-radius: 30rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.modalDlg .title{
  text-align: center;
  font-size: 45rpx;
  font-weight: bold;
}
.modalBtnCommon{
  width: 50%;
  background-color: white;
  text-align: center;
  line-height: 100rpx;
  font-size: 35rpx;
  border-top: 1px solid rgba(168, 161, 161, 0.5);
}
.modalBtnBox{
  display: flex;
  justify-content: space-between;
  width: 100%;
  height:150rpx;
}
.modalBtnL{
  border-bottom-left-radius: 30rpx;
}
.modalBtnR{
  color: #576B95;
  border-left:1px solid rgba(168, 161, 161, 0.5);
  border-bottom-right-radius: 30rpx;
}

.js:

// 自定义弹框
enter: function() {
  this.setData({
    showModal: false
  })
},

preventTouchMove: function() {

},
cancel: function() { 
  this.setData({
  showModal: false
  })
 }

需要注意的地方:
蒙层view中绑定的preventTouchMove函数是一个空函数,使用了catch事件,目的就是阻止touchmove这样一个冒泡事件继续向下传递。

觉得好的话,轻轻鼓励一下吧!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值