亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

微信小程序自定義支持圖片的彈窗

 更新時(shí)間:2022年07月07日 14:37:20   作者:歲末Zzz  
這篇文章主要為大家詳細(xì)介紹了微信小程序自定義支持圖片的彈窗,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序自定義支持圖片的彈窗,供大家參考,具體內(nèi)容如下

為index.wxml添加如下圖代碼: (微信小程序 - canvas層級(jí)最高問題,如何超越canvas的層級(jí),只能使用cover-view標(biāo)簽)

<!--index.wxml-->

<button class="show-btn" bindtap="showDialogBtn">彈窗</button>

<!--彈窗-->

<cover-view class="modal-mask" bindtap="hideModal" wx:if="{{modal.isShow}}"></cover-view>
<cover-view class="modal-dialog" wx:if="{{modal.isShow}}" >
 <cover-view class="modal-title">{{modal.title}}</cover-view>
 <cover-view class="modal-content">
 <cover-image src="{{modal.src}}" class="img-full" style="height:auto;" mode="widthFix"></cover-image>
 </cover-view>
 <cover-view class="modal-footer" wx-if="{{modal.isFooter}}">
 <cover-view class="btn-cancel" bindtap="onCancel" data-status="cancel">{{modal.cancel}}</cover-view>
 <cover-viewew class="btn-confirm" bindtap="onConfirm" data-status="confirm">{{modal.ok}}</cover-viewew>
 </cover-view>
</cover-view>

修改樣式文件index.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: 36rpx;
}
.modal-title {
 padding-top: 50rpx;
 font-size: 36rpx;
 color: #030303;
 text-align: center;
}
.modal-content {
 padding: 50rpx 32rpx;
}
.modal-input {
 display: flex;
 background: #fff;
 border: 2rpx solid #ddd;
 border-radius: 4rpx;
 font-size: 28rpx;
}
.input {
 width: 100%;
 height: 82rpx;
 font-size: 28rpx;
 line-height: 28rpx;
 padding: 0 20rpx;
 box-sizing: border-box;
 color: #333;
}
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: #666;
 text-align: center;
 border-right: 1px solid #dedede;
}
.btn-confirm {
 width: 50%;
 color: #ec5300;
 text-align: center;
}

index.js代碼如下圖所示:

//index.js
//獲取應(yīng)用實(shí)例
var app = getApp()
Page({
 data: {
 showModal: false,
 },
 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 () {
 this.hideModal();

 }

})

運(yùn)行,可以看到修改樣式后的效果

這里有個(gè)要特別注意的地方,就是下面這個(gè)方法:

preventTouchMove: function () { }

為什么是空方法?因?yàn)橐Y(jié)合界面wxml看,蒙層view里有一個(gè)事件綁定

catchtouchmove="preventTouchMove"。

這樣寫的原因是阻斷事件向下傳遞,避免在彈窗后還可以點(diǎn)擊或者滑動(dòng)蒙層下的界面。

如果不這樣寫的話,如果主界面是一個(gè)可以滾動(dòng)的界面,想想看,當(dāng)彈窗彈出的時(shí)候用戶還可以操作滾動(dòng)列表。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論