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

wxml代碼:
<view class='fix_bottom'>
<view>分享</view>
<view>電話咨詢</view>
<view class='active' bindtap="showDialogBtn">立即報名</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='小學升初中'
Page({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
showModal: false,
concent_list:['小學升初中','初一升初二','初二升初三','初中升高中'],
curindex:-1
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面顯示
*/
onShow: function () {
},
/**
* 彈窗
*/
showDialogBtn: function () {
this.setData({
showModal: true
})
},
/**
* 隱藏模態(tài)對話框
*/
hideModal: function () {
this.setData({
showModal: false
});
},
/**
* 對話框取消按鈕點擊事件
*/
onCancel: function () {
this.hideModal();
},
/**
* 對話框確認按鈕點擊事件
*/
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)框顯示時禁止底部內(nèi)容滾動可以在彈出時給底部包裹部分加上固定定位,模態(tài)框隱藏時取消固定定位
內(nèi)容包裹的元素需要設置100%的寬度
<view class='diceng_wrap' style='position: {{position}}'>
底部所有內(nèi)容內(nèi)容內(nèi)容
</view>
data數(shù)據(jù)的變化:
初始化時:
position: 'auto',
模態(tài)框顯示時:
position: 'fixed',
模態(tài)框隱藏時:
position: 'auto',
模態(tài)框顯示時
總結(jié)
到此這篇關(guān)于微信小程序自定義彈出模態(tài)框禁止底部滾動功能的文章就介紹到這了,更多相關(guān)微信小程序彈出模態(tài)框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS驗證輸入的是否是數(shù)字及保留幾位小數(shù)問題
這篇文章主要介紹了JS驗證輸入的是否是數(shù)字及保留幾位小數(shù)問題,非常不錯,具有一定的參考借鑒價值,需要的朋友參考下吧2018-05-05
JS頁面刷新與重新加載功能實現(xiàn)(關(guān)閉當前窗口)
在計算機網(wǎng)頁中如果我們想獲取當前頁面最新的內(nèi)容,可以刷新當前頁面重新獲取數(shù)據(jù),這篇文章主要給大家介紹了關(guān)于JS頁面刷新與重新加載功能實現(xiàn)(關(guān)閉當前窗口)的相關(guān)資料,需要的朋友可以參考下2023-10-10
javascript讓setInteval里的函數(shù)參數(shù)中的this指向特定的對象
話說阿里巴巴今年的校園招聘有一道題目考了一個知識點,那就是setInterval的參數(shù)函數(shù)里的this指向.2010-01-01

