微信小程序?qū)W習(xí)之自定義滾動(dòng)彈窗
微信小程序雖然有三種自帶的彈窗,但是畢竟功能有限,有時(shí)候難以滿足我們的需求,所以我們可以自己嘗試制作自定義彈窗,話不多說,直接上圖:


其中列表部分支持滾動(dòng),所以信息承載能力很強(qiáng)。
實(shí)現(xiàn)代碼:
wxml:
<button class="showModal" bindtap="showModal_click">喚出彈窗</button>
<!--彈窗-->
<view class="modal-mask" bindtap="hideModal" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>
<view class="modal-dialog" wx:if="{{showModal}}">
<view class="modal-title">標(biāo)題</view>
<view class="modal-title-sc">副標(biāo)題</view>
<view class="modal-content">
<scroll-view scroll-y="true" style="height:100px;">
<block wx:for="{{data}}" wx:key="id">
<button class="info">
<view class="name_List">{{item.name}}</view>
<view class="quantity_List">×{{item.quantity}}</view>
<view class="reason_List">{{item.message}}</view>
</button>
</block>
</scroll-view>
</view>
<view class="modal-content-return">
此處可隨意添加文本內(nèi)容
</view>
<view class="modal-footer">
<view class="btn-cancel" bindtap="onCancel" data-status="cancel">取消</view>
<view class="btn-confirm" bindtap="onConfirm" data-status="confirm">確定</view>
</view>
</view>
wxss:
.showModal{
position:absolute;
height:50px;
left:30%;
width:40%;
top:40%;
background: rgb(95, 228, 83);
color:#fff;
font-size: 20px;
}
/*以下全是彈窗樣式*/
.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: 80%;
overflow: hidden;
position: fixed;
top: 40%;
left: 0;
z-index: 9999;
background: #f9f9f9;
margin-top: -180rpx;
margin-left: 10%;
border-radius: 36rpx;
}
.modal-title {
padding-top: 30rpx;
font-size: 20px;
color: #030303;
text-align: center;
}
.modal-title-sc {
padding-top: 10rpx;
font-size: 15px;
color: #bebcbc;
text-align: center;
}
.modal-content {
padding: 10rpx 32rpx;
}
.info{
height:30px;
left:0%;
text-align: left;
font-size: 12px;
color:#bebcbc;
}
.info::after{
border: 0px;
}
.name_List{
position:absolute;
left:0%;
width:40%;
text-align: left;
}
.quantity_List{
position:absolute;
left:40%;
width:10%;
text-align: left;
}
.reason_List{
position:absolute;
left:50%;
width:50%;
text-align: right;
overflow: hidden;
}
.modal-content-return{
padding: 15rpx 32rpx;
font-size: 15px;
color: #bebcbc;
}
.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;
}
js:
Page({
data: {
data:null,
showModal:false
},
onLoad: function () {
var data=[
{id:1,name:"cc",quantity:2,message:"愛玩游戲"},
{id:2,name:"ha",quantity:4,message:"愛談戀愛"},
{id:3,name:"lxl",quantity:6,message:"愛看電視"},
{id:4,name:"cc",quantity:2,message:"愛玩游戲"},
{id:5,name:"ha",quantity:4,message:"愛談戀愛"},
{id:6,name:"lxl",quantity:6,message:"愛看電視"},
]
this.setData({
data:data
})
},
showModal_click:function(){
this.setData({
showModal:true
})
},
//彈窗事件
hideModal: function () {
this.setData({
showModal: false
});
},
onCancel: function () {
this.hideModal();
},
onConfirm: function () {
this.hideModal();
}
})
直接拿過去就可以用,data里面的內(nèi)容可以動(dòng)態(tài)獲取
到此這篇關(guān)于微信小程序?qū)W習(xí)之自定義滾動(dòng)彈窗的文章就介紹到這了,更多相關(guān)微信小程序自定義滾動(dòng)彈窗內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- 微信小程序自定義彈窗滾動(dòng)與頁面滾動(dòng)沖突的解決方法
- 微信小程序?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í)例代碼
相關(guān)文章
JS使用for in有序獲取對(duì)象數(shù)據(jù)
這篇文章主要介紹了JS使用for in有序獲取對(duì)象數(shù)據(jù),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-05-05
Bootstrap學(xué)習(xí)筆記之css樣式設(shè)計(jì)(1)
這篇文章主要為大家詳細(xì)介紹了bootstrap學(xué)習(xí)筆記之css樣式設(shè)計(jì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-06-06
使用Fuse.js實(shí)現(xiàn)高效的模糊搜索功能
在現(xiàn)代?Web?應(yīng)用程序中,實(shí)現(xiàn)高效的搜索功能是至關(guān)重要的,Fuse.js?是一個(gè)強(qiáng)大的?JavaScript?庫,它提供了靈活的模糊搜索和文本匹配功能,使您能夠輕松實(shí)現(xiàn)出色的搜索體驗(yàn),文中代碼示例講解的非常詳細(xì),需要的朋友可以參考下2024-01-01
javascript中函數(shù)的寫法實(shí)例代碼詳解
這篇文章主要介紹了javascript中函數(shù)的寫法 ,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-10-10

