2.微信小程序-自定义弹框
参考:https://blog.csdn.net/zhuyb829/article/details/73349295
由于小程序自带的模态框设置样式会错乱所以得自定义模态框现将相关代码贴出来,以后备用。
1.页面
<!--sos模态框--> <view class="modal-mask" bindtap="hideModal" catchtouchmove="preventTouchMove" wx:if="{{modal.sos}}"></view> <view class="modal-dialog" wx:if="{{modal.sos}}"> <view class="modal-title">SOS/亲情号码</view> <view class="modal-content"> <view class=\'modal-input-content\'> <view class=\'modal-input-title\'><text>号码1:</text></view> <input class="modal-input" placeholder-class="input-holder" type="number" maxlength="19" bindinput="inputChange" class="input" placeholder="{{hint}}"></input> </view> <view class=\'modal-input-content\'> <view class=\'modal-input-title\'><text>号码2:</text></view> <input class="modal-input" placeholder-class="input-holder" type="number" maxlength="19" bindinput="inputChange" class="input" placeholder="{{hint}}"></input> </view> <view class=\'modal-input-content\'> <view class=\'modal-input-title\'><text>号码3:</text></view> <input class="modal-input" placeholder-class="input-holder" type="number" maxlength="19" bindinput="inputChange" class="input" placeholder="{{hint}}"></input> </view> </view> <view class="modal-footer"> <view class="btn-cancel" bindtap="sosCancel" data-status="cancel">取消</view> <view class="btn-confirm" bindtap="sosConfirm" data-status="confirm">确定</view> </view> </view>
2.css
.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: 40%; left: 0; z-index: 9999; background: #fff; margin: -180rpx 105rpx; border-radius: 10rpx; } .modal-title { padding-top: 25rpx; padding-bottom: 25rpx; font-size: 36rpx; line-height: 36rpx; color: #030303; text-align: center; background-color: #FF9106; } .modal-content { padding: 0rpx 26rpx 26rpx 26rpx; } .modal-input-content{ display: flex; flex-direction: row; margin-top: 26rpx; } .modal-input-title { font-size: 28rpx; line-height: 30rpx; padding-top: 26rpx; } .modal-input { display: flex; background: #fff; font-size: 28rpx; } .input { width: 74%; height: 82rpx; font-size: 28rpx; line-height: 28rpx; padding: 0 5rpx; box-sizing: border-box; color: #333; border: 1rpx solid #FF9106; border-radius: 10rpx; margin-left: 10rpx; } input-holder { color: #666; font-size: 28rpx; } .modal-footer { display: flex; flex-direction: row; height: 86rpx; border-top: 1px solid #dedede; font-size: 34rpx; line-height: 86rpx; } .btn-cancel { width: 50%; color: #fff; text-align: center; border-right: 1px solid #dedede; background-color: #FF9106; } .btn-confirm { width: 50%; color: #fff; text-align: center; background-color: #FF9106; }
模态框的弹入弹出需要再对应页面js文件中的modal.sos控制,弹出的话绑定相关事件定义方法就行了。至于参考博客中所说的蒙版页面会移动,我这里是没碰到。可能是由于我手上的工程是由于tab是自定义的原因。
版权声明:本文为Nick-Hu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。