微信小程序自定義模態(tài)框
本文實(shí)例為大家分享了微信小程序自定義模態(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">恭喜你,成功加入班級(jí)</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
? ? })
? },
? /**
? ?* 彈出框蒙層截?cái)鄑ouchmove事件
? ?*/
? preventTouchMove: function () {},
? /**
? ?* 隱藏模態(tài)對(duì)話框
? ?*/
? hideModal: function () {
? ? this.setData({
? ? ? showModal: false
? ? });
? },
? /**
? ?* 對(duì)話框取消按鈕點(diǎn)擊事件
? ?*/
? onCancel: function () {
? ? this.hideModal();
? },
? /**
? ?* 對(duì)話框確認(rèn)按鈕點(diǎn)擊事件
? ?*/
? onConfirm: function (e) {
? ? console.log(e.currentTarget.dataset.name);
? ? this.hideModal();
? }
})以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
javascript 中iframe高度自適應(yīng)(同域)實(shí)例詳解
這篇文章主要介紹了javascript 中iframe高度自適應(yīng)(同域)實(shí)現(xiàn)代碼的相關(guān)資料,需要的朋友可以參考下2017-05-05
才發(fā)現(xiàn)的超鏈接js導(dǎo)致網(wǎng)頁(yè)中GIF動(dòng)畫停止的解決方法
才發(fā)現(xiàn)的超鏈接js導(dǎo)致網(wǎng)頁(yè)中GIF動(dòng)畫停止的解決方法...2007-11-11
HTML頁(yè)面滾動(dòng)時(shí)獲取離頁(yè)面頂部的距離2種實(shí)現(xiàn)方法
獲取離滾動(dòng)頁(yè)面的頂部距離有兩種方法一是DOM;而是jquery,具體的實(shí)現(xiàn)如下,感興趣的朋友可以嘗試操作下2013-09-09
JS當(dāng)前頁(yè)面登錄注冊(cè)框,固定DIV,底層陰影的實(shí)例代碼
下面小編就為大家?guī)硪黄狫S當(dāng)前頁(yè)面登錄注冊(cè)框,固定DIV,底層陰影的實(shí)例代碼。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-09-09
轉(zhuǎn)換json格式的日期為Javascript對(duì)象的函數(shù)
項(xiàng)目中碰到了用jQuery從后臺(tái)獲取的json格式的日期的字符串,需要將此字符串轉(zhuǎn)換成JavaScript的日期對(duì)象,記在此處,以備后用。2010-07-07

