微信小程序自定義彈出模態(tài)框禁止底部滾動(dòng)功能
圖示:

wxml代碼:
<view class='fix_bottom'>
<view>分享</view>
<view>電話咨詢</view>
<view class='active' bindtap="showDialogBtn">立即報(bào)名</view>
</view>
<!--模態(tài)框-->
<!-- 遮罩層 -->
<view class="modal-mask" bindtap="hideModal" catchtouchmove="preventTouchMove" wx:if="{{showModal}}"></view>
<view class="modal-dialog" wx:if="{{showModal}}">
<view class="modal-title">選擇班次</view>
<view class="modal-content">
<view class="concent_list {{curindex==index? 'active':''}}" wx:for="{{concent_list}}" wx:for-index='index' data-index='{{index}}' bindtap='choose' data-name='{{item}}'>{{item}}</view>
</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代碼
.fix_bottom{
width: 100%;
height: 120rpx;
background: #fff;
position: fixed;
bottom: 0;
border-top: 1px solid #ccc;
display: flex;
}
.fix_bottom view{
width: 33.333%;
border-left: 1px solid #ccc;
line-height: 120rpx;
text-align: center;
font-size: 40rpx;
font-weight: bold;
}
.active{
color:#ffffff;
background: -moz-linear-gradient(left, #ff7b68, #ff5462);
/* Safari 4-5, Chrome 1-9 */
/* -webkit-gradient(, [, ]?, [, ]? [, ]*) */
background: -webkit-gradient(linear,left,from(#ff7b68),to(#ff5462));
/* Safari 5.1+, Chrome 10+ */
background: -webkit-linear-gradient(left, #ff7b68, #ff5462);
/* Opera 11.10+ */
background: -o-linear-gradient(left, #ff7b68, #ff5462);
}
/* 模態(tài)框 */
.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: 40%;
left: 0;
z-index: 9999;
background: #f9f9f9;
margin: -180rpx 105rpx;
border-radius: 36rpx;
}
.modal-title {
height: 100rpx;
line-height: 100rpx;
font-size: 36rpx;
color: #fff;
text-align: center;
background: -moz-linear-gradient(left, #ff7b68, #ff5462);
/* Safari 4-5, Chrome 1-9 */
/* -webkit-gradient(, [, ]?, [, ]? [, ]*) */
background: -webkit-gradient(linear,left,from(#ff7b68),to(#ff5462));
/* Safari 5.1+, Chrome 10+ */
background: -webkit-linear-gradient(left, #ff7b68, #ff5462);
/* Opera 11.10+ */
background: -o-linear-gradient(left, #ff7b68, #ff5462);
border-bottom: 1px solid #ccc;
}
.modal-content {
}
.concent_list{
width: 100%;
height: 100rpx;
border-bottom: 1px solid #ccc;
line-height: 100rpx;
text-align: center;
}
.modal-footer {
display: flex;
flex-direction: row;
height: 86rpx;
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代碼
var value='小學(xué)升初中'
Page({
/**
* 頁(yè)面的初始數(shù)據(jù)
*/
data: {
showModal: false,
concent_list:['小學(xué)升初中','初一升初二','初二升初三','初中升高中'],
curindex:-1
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載
*/
onLoad: function (options) {
},
/**
* 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面顯示
*/
onShow: function () {
},
/**
* 彈窗
*/
showDialogBtn: function () {
this.setData({
showModal: true
})
},
/**
* 隱藏模態(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();
})
},
choose:function(e){
var index=e.currentTarget.dataset.index
value = e.currentTarget.dataset.name
console.log(value)
this.setData({
curindex:index
})
}
})
模態(tài)框顯示時(shí)禁止底部?jī)?nèi)容滾動(dòng)可以在彈出時(shí)給底部包裹部分加上固定定位,模態(tài)框隱藏時(shí)取消固定定位
內(nèi)容包裹的元素需要設(shè)置100%的寬度
<view class='diceng_wrap' style='position: {{position}}'>
底部所有內(nèi)容內(nèi)容內(nèi)容
</view>
data數(shù)據(jù)的變化:
初始化時(shí):
position: 'auto',
模態(tài)框顯示時(shí):
position: 'fixed',
模態(tài)框隱藏時(shí):
position: 'auto',
模態(tài)框顯示時(shí)
總結(jié)
到此這篇關(guān)于微信小程序自定義彈出模態(tài)框禁止底部滾動(dòng)功能的文章就介紹到這了,更多相關(guān)微信小程序彈出模態(tài)框內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS驗(yàn)證輸入的是否是數(shù)字及保留幾位小數(shù)問(wèn)題
這篇文章主要介紹了JS驗(yàn)證輸入的是否是數(shù)字及保留幾位小數(shù)問(wèn)題,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2018-05-05
JS頁(yè)面刷新與重新加載功能實(shí)現(xiàn)(關(guān)閉當(dāng)前窗口)
在計(jì)算機(jī)網(wǎng)頁(yè)中如果我們想獲取當(dāng)前頁(yè)面最新的內(nèi)容,可以刷新當(dāng)前頁(yè)面重新獲取數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于JS頁(yè)面刷新與重新加載功能實(shí)現(xiàn)(關(guān)閉當(dāng)前窗口)的相關(guān)資料,需要的朋友可以參考下2023-10-10
javascript讓setInteval里的函數(shù)參數(shù)中的this指向特定的對(duì)象
話說(shuō)阿里巴巴今年的校園招聘有一道題目考了一個(gè)知識(shí)點(diǎn),那就是setInterval的參數(shù)函數(shù)里的this指向.2010-01-01
基于JS實(shí)現(xiàn)省市聯(lián)動(dòng)效果代碼分享
這篇文章主要介紹了基于JS實(shí)現(xiàn)省市聯(lián)動(dòng)效果代碼的相關(guān)資料,非常實(shí)用,在日常項(xiàng)目開(kāi)發(fā)過(guò)程中經(jīng)常遇到此需求,下面小編給大家分享實(shí)現(xiàn)代碼,需要的朋友可以參考下2016-06-06
淺析創(chuàng)建javascript對(duì)象的方法
下面小編就為大家?guī)?lái)一篇淺析創(chuàng)建javascript對(duì)象的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-05-05

