微信小程序自定義模態(tài)框
更新時間:2022年07月05日 09:31:02 作者:A~小鯨喜
這篇文章主要為大家詳細介紹了微信小程序自定義模態(tài)框,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了微信小程序自定義模態(tài)框的具體代碼,供大家參考,具體內(nèi)容如下
效果展示
可在模態(tài)框中添加圖片輸入框

代碼展示-wxml
<button class="show-btn" bindtap="showDialogBtn">彈窗</button>
? ? <view
? ? ? class="modal-mask"
? ? ? bindtap="hideModal"
? ? ? catchtouchmove="preventTouchMove"
? ? ? wx:if="{{showModal}}"
? ? ></view>
? ? <!-- 成功 -->
? ? <view class="modal-dialog" wx:if="{{showModal && ses}}">
? ? ? <view class="modal-img">
? ? ? ? <image src="/image/indexImg/sesImg.png" mode="widthFix" />
? ? ? </view>
? ? ? <view class="modal-title">恭喜你,成功加入班級</view>
? ? ? <view class="modal-footer">
? ? ? ? <view
? ? ? ? ? class="btn-confirms"
? ? ? ? ? bindtap="onConfirm"
? ? ? ? ? data-status="confirm"
? ? ? ? ? data-name="{{name}}"
? ? ? ? >確定
? ? ? ? </view>
? ? ? </view>
</view>代碼展示-wxss
/**index.wxss**/
? ? .show-btn {
? ? ? ? margin-top: 100rpx;
? ? ? ? color: #22cc22;
? ? }
?
? ? .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: 8px;
? ? }
?
? ? .modal-title {
? ? ? ? padding-top: 30rpx;
? ? ? ? padding-bottom: 30rpx;
? ? ? ? font-size: 14px;
? ? ? ? color: #030303;
? ? ? ? text-align: center;
? ? }
?
? ? .modal-img {
? ? ? ? width: 40px;
? ? ? ? height: 40px;
? ? ? ? margin: 0 auto;
? ? ? ? margin-top: 20rpx;
?
? ? ? ? image {
? ? ? ? ? ? width: 100%;
? ? ? ? ? ? height: 100%;
? ? ? ? }
? ? }
?
?
? ? .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: #8f8f8f;
? ? ? ? background-color: #f2f2f2;
? ? ? ? text-align: center;
? ? ? ? border-right: 1px solid #dedede;
? ? }
?
? ? .btn-confirm {
? ? ? ? width: 50%;
? ? ? ? color: #8f8f8f;
? ? ? ? background-color: #f2f2f2;
? ? ? ? text-align: center;
? ? }
?
? ? .btn-confirms {
? ? ? ? width: 100%;
? ? ? ? background-color: #f2f2f2;
? ? ? ? color: #8f8f8f;
? ? ? ? text-align: center;
? ? }代碼展示-js
var app = getApp()
Page({
? data: {
? ? showModal: false,
? ? // 成功
? ? ses:true,
? },
? onLoad: function () {},
? /**
? ?* 彈窗
? ?*/
?
? showDialogBtn: function () {
? ? this.setData({
? ? ? showModal: true
? ? })
? },
? /**
? ?* 彈出框蒙層截斷touchmove事件
? ?*/
? preventTouchMove: function () {},
? /**
? ?* 隱藏模態(tài)對話框
? ?*/
? hideModal: function () {
? ? this.setData({
? ? ? showModal: false
? ? });
? },
? /**
? ?* 對話框取消按鈕點擊事件
? ?*/
? onCancel: function () {
? ? this.hideModal();
? },
? /**
? ?* 對話框確認按鈕點擊事件
? ?*/
? onConfirm: function (e) {
? ? console.log(e.currentTarget.dataset.name);
? ? this.hideModal();
? }
})以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript 中iframe高度自適應(同域)實例詳解
這篇文章主要介紹了javascript 中iframe高度自適應(同域)實現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05
才發(fā)現(xiàn)的超鏈接js導致網(wǎng)頁中GIF動畫停止的解決方法
才發(fā)現(xiàn)的超鏈接js導致網(wǎng)頁中GIF動畫停止的解決方法...2007-11-11
HTML頁面滾動時獲取離頁面頂部的距離2種實現(xiàn)方法
獲取離滾動頁面的頂部距離有兩種方法一是DOM;而是jquery,具體的實現(xiàn)如下,感興趣的朋友可以嘗試操作下2013-09-09
轉(zhuǎn)換json格式的日期為Javascript對象的函數(shù)
項目中碰到了用jQuery從后臺獲取的json格式的日期的字符串,需要將此字符串轉(zhuǎn)換成JavaScript的日期對象,記在此處,以備后用。2010-07-07

