微信小程序自定義支持圖片的彈窗
本文實(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ì)話框
*/
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í)有所幫助,也希望大家多多支持腳本之家。
- 微信小程序?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)方式
- 微信小程序用戶授權(quán)彈窗 拒絕時(shí)引導(dǎo)用戶重新授權(quán)實(shí)現(xiàn)
- 微信小程序 彈窗自定義實(shí)例代碼
- 微信小程序日歷彈窗選擇器代碼實(shí)例
相關(guān)文章
整理一些JavaScript的IE和火狐的兼容性注意事項(xiàng)
整理一些JavaScript的IE和火狐的兼容性解決方法,有更好的方法多多交流2011-03-03
解決ueditor jquery javascript 取值問(wèn)題
這篇文章主要介紹了解決ueditor jquery javascript 取值問(wèn)題,需要的朋友可以參考下2014-12-12
JS實(shí)現(xiàn)為排序好的字符串找出重復(fù)行的方法
這篇文章主要介紹了JS實(shí)現(xiàn)為排序好的字符串找出重復(fù)行的方法,涉及JavaScript字符串運(yùn)算相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-03-03
javascript中的數(shù)據(jù)類型檢測(cè)方法詳解
這篇文章主要介紹了javascript中的數(shù)據(jù)類型檢測(cè)方法,結(jié)合實(shí)例形式分析了javascript數(shù)據(jù)類型并總結(jié)分析了常見(jiàn)的數(shù)據(jù)類型檢測(cè)操作技巧,需要的朋友可以參考下2019-08-08
使用CSS3的scale實(shí)現(xiàn)網(wǎng)頁(yè)整體縮放
QQ郵箱的網(wǎng)頁(yè)整體縮放效果,原來(lái)實(shí)現(xiàn)方法如此簡(jiǎn)單,下面有個(gè)實(shí)現(xiàn)示例,大家可以參考下2014-03-03

