小程序自定义弹框

在这里插入图片描述

wxml

<view class='cardNum'>
	<text catchtap='showDialogBtn'>解除绑定</text>
</view>
<!--弹窗-->
<view class="modal-mask" bindtap="hideModal" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>
<view class="modal-dialog" wx:if="{{showModal}}">
	<view class="modal-content">
		解除板顶后银行卡服务将不可使用
	</view>
	<view class="modal-footer">
		<view class="btn-cancel" bindtap="hideModal" data-status="cancel">取消</view>
		<view class="btn-confirm" bindtap="onConfirm" data-status="confirm">确定</view>
	</view>
</view>

js

data: {
    showModal: false,
  },
  showDialogBtn: function () {
    var that = this
    that.setData({
      showModal: true
    })
  },
  /**
   * 隐藏模态对话框
   */
  hideModal: function () {
    var that = this
    that.setData({
      showModal: false
    });
  },

wxss

.cardNum text{
    background: white;
    float: right;
    padding: 5rpx 10rpx;
    border-radius: 8rpx;
    font-size: 24rpx;
    color:#a53533;
    margin-right: 30rpx;
    }
    
    .modal-mask {
      width: 100%;
      height: 100%;
      position: fixed;
      top: 0;
      left: 0;
      background: #000;
      opacity: 0.5;
      overflow: hidden;
      z-index: 9000;
      color: #fff;
    }
    .modal-dialog {
      width: 540rpx;
      overflow: hidden;
      position: fixed;
      top: 50%;
      left: 0;
      z-index: 9999;
      background: #f9f9f9;
      margin: -180rpx 105rpx;
      border-radius: 8rpx;
    } 
    .modal-content {
      padding: 50rpx 0rpx;
      text-align: center;
      color: #666
    }
    .modal-footer {
      display: flex;
      flex-direction: row;
      height: 86rpx;
      border-top: 1px solid #dedede;
      font-size: 32rpx;
      line-height: 86rpx;
    }
    .btn-cancel {
      width: 50%;
      color: #666;
      text-align: center;
      border-right: 1px solid #dedede;
    }
    .btn-confirm {
      width: 50%;
       background:#a53533;
      color: white;
      text-align: center;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的示例代码,可以用于在微信小程序中创建一个自定义弹框: 在 WXML 文件中,添加以下代码: ``` <!-- 弹框 --> <view class="mask" hidden="{{!showModal}}"></view> <view class="modal" hidden="{{!showModal}}"> <view class="modal-title">{{modalTitle}}</view> <view class="modal-content">{{modalContent}}</view> <view class="modal-footer"> <button class="modal-cancel" bindtap="onModalCancel">取消</button> <button class="modal-confirm" bindtap="onModalConfirm">确定</button> </view> </view> ``` 在 JS 文件中,添加以下代码: ``` Page({ data: { showModal: false, // 控制弹框显示隐藏的变量 modalTitle: '', // 弹框标题 modalContent: '', // 弹框内容 }, // 点击按钮弹出弹框 showCustomModal: function() { this.setData({ showModal: true, modalTitle: '提示', modalContent: '您确定要进行此操作吗?', }) }, // 点击弹框取消按钮 onModalCancel: function() { this.setData({ showModal: false, }) }, // 点击弹框确定按钮 onModalConfirm: function() { // 进行需要的操作 this.setData({ showModal: false, }) }, }) ``` 在 WXSS 文件中,添加以下代码: ``` /* 弹框样式 */ .mask { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); } .modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; border-radius: 8rpx; padding: 20rpx; text-align: center; } .modal-title { font-size: 34rpx; font-weight: bold; margin-bottom: 20rpx; } .modal-content { font-size: 28rpx; margin-bottom: 40rpx; } .modal-footer { display: flex; justify-content: space-between; } .modal-cancel, .modal-confirm { flex: 1; background-color: #eee; border-radius: 8rpx; padding: 10rpx; font-size: 28rpx; margin-right: 20rpx; } .modal-confirm { background-color: #4caf50; color: #fff; } ``` 这样,一个简单的自定义弹框就完成了。您可以根据需求自行修改样式和功能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值