微信小程序自定義模態(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)文章
JS驗證input輸入框(字母,數(shù)字,符號,中文)
本文主要介紹了JS驗證input輸入框(字母,數(shù)字,符號,中文)的方法。具有很好的參考價值。下面跟著小編一起來看下吧2017-03-03細說JS數(shù)組遍歷的一些細節(jié)及實現(xiàn)
本文主要介紹了細說JS數(shù)組遍歷的一些細節(jié)及實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-05-05javascript 得到文件后綴名的思路及實現(xiàn)
在上傳文件時,常常要對文件的類型即對文件的后綴名進行判斷,用javascript可以很容易的做到這一點。用Javascript解析一個帶絕對路徑的文件名并得到后綴名的方法有很多種,這里列出一種,以供參考。2013-07-07JavaScript計時器用法分析【setTimeout和clearTimeout】
這篇文章主要介紹了JavaScript計時器用法,結(jié)合實例形式分析了setTimeout和clearTimeout函數(shù)的具體使用技巧,需要的朋友可以參考下2017-01-01JS判斷輸入的字符串是否是數(shù)字的方法(正則表達式)
下面小編就為大家?guī)硪黄狫S判斷輸入的字符串是否是數(shù)字的方法(正則表達式)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11