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是自定義的原因。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM