微信小程序自定義支持圖片的彈窗
本文實(shí)例為大家分享了微信小程序自定義支持圖片的彈窗,供大家參考,具體內(nèi)容如下
為index.wxml添加如下圖代碼: (微信小程序 - canvas層級(jí)最高問(wèn)題,如何超越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ì)話(huà)框
*/
hideModal: function () {
this.setData({
showModal: false
});
},
/**
* 對(duì)話(huà)框取消按鈕點(diǎn)擊事件
*/
onCancel: function () {
this.hideModal();
},
/**
* 對(duì)話(huà)框確認(rèn)按鈕點(diǎn)擊事件
*/
onConfirm: function () {
this.hideModal();
}
})運(yùn)行,可以看到修改樣式后的效果
這里有個(gè)要特別注意的地方,就是下面這個(gè)方法:
preventTouchMove: function () { }為什么是空方法?因?yàn)橐Y(jié)合界面wxml看,蒙層view里有一個(gè)事件綁定
catchtouchmove="preventTouchMove"。
這樣寫(xiě)的原因是阻斷事件向下傳遞,避免在彈窗后還可以點(diǎn)擊或者滑動(dòng)蒙層下的界面。
如果不這樣寫(xiě)的話(huà),如果主界面是一個(gè)可以滾動(dòng)的界面,想想看,當(dāng)彈窗彈出的時(shí)候用戶(hù)還可以操作滾動(dòng)列表。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?qū)崙?zhàn)之自定義模態(tài)彈窗(8)
- 微信小程序常用的3種提示彈窗實(shí)現(xiàn)詳解
- 微信小程序?qū)崿F(xiàn)自定義modal彈窗封裝的方法
- 微信小程序?qū)崿F(xiàn)自定義picker選擇器彈窗內(nèi)容
- 微信小程序?qū)崿F(xiàn)漂亮的彈窗效果
- 微信小程序自定義彈窗實(shí)現(xiàn)詳解(可通用)
- 微信小程序vant彈窗組件的實(shí)現(xiàn)方式
- 微信小程序用戶(hù)授權(quán)彈窗 拒絕時(shí)引導(dǎo)用戶(hù)重新授權(quán)實(shí)現(xiàn)
- 微信小程序 彈窗自定義實(shí)例代碼
- 微信小程序日歷彈窗選擇器代碼實(shí)例
相關(guān)文章
JavaScript實(shí)現(xiàn)的雙向跨域插件分享
這篇文章主要介紹了JavaScript實(shí)現(xiàn)的雙向跨域插件分享,本文實(shí)現(xiàn)把整個(gè)跨域過(guò)程抽象出來(lái),封裝成一個(gè)JavaScript插件,需要的朋友可以參考下2015-01-01
微信小程序轉(zhuǎn)盤(pán)抽獎(jiǎng)的實(shí)現(xiàn)方法
這篇文章主要為大家詳細(xì)介紹了微信小程序轉(zhuǎn)盤(pán)抽獎(jiǎng)的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-07-07
JS讀取XML文件數(shù)據(jù)并以table形式顯示數(shù)據(jù)的方法(兼容IE與火狐)
這篇文章主要介紹了JS讀取XML文件數(shù)據(jù)并以table形式顯示數(shù)據(jù)的方法,涉及javascript針對(duì)xml節(jié)點(diǎn)操作及HTML表格操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-06-06
javascript 根據(jù)指定字符把字符串拆分為數(shù)組
javascript 根據(jù)指定字符把字符串拆分為數(shù)組2009-05-05

