微信小程序自定義彈出模態(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({
/**
* 頁面的初始數(shù)據(jù)
*/
data: {
showModal: false,
concent_list:['小學(xué)升初中','初一升初二','初二升初三','初中升高中'],
curindex:-1
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面加載
*/
onLoad: function (options) {
},
/**
* 生命周期函數(shù)--監(jiān)聽頁面顯示
*/
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í)禁止底部內(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)文章
javascript中運(yùn)用閉包和自執(zhí)行函數(shù)解決大量的全局變量問題
做為一個(gè)javascript新手,為了程式的簡(jiǎn)便,可能會(huì)在javascript中運(yùn)用了大量的全局變量,雖然一時(shí)看來,問題解決了,而且也可能讓編碼變得更加的簡(jiǎn)單。2010-12-12
根據(jù)輸入郵箱號(hào)跳轉(zhuǎn)到相應(yīng)登錄地址的解決方法
本文分享了基于javascript實(shí)現(xiàn)的根據(jù)輸入郵箱號(hào)跳轉(zhuǎn)到相應(yīng)登錄地址的具體實(shí)例代碼,需要的朋友一起來看下吧2016-12-12
JS獲取表格內(nèi)指定單元格html內(nèi)容的方法
這篇文章主要介紹了JS獲取表格內(nèi)指定單元格html內(nèi)容的方法,涉及javascript中innerHTML屬性的使用技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03
JavaScript將當(dāng)前時(shí)間轉(zhuǎn)換成UTC標(biāo)準(zhǔn)時(shí)間的方法
這篇文章主要介紹了JavaScript將當(dāng)前時(shí)間轉(zhuǎn)換成UTC標(biāo)準(zhǔn)時(shí)間的方法,涉及javascript中Date及toUTCString方法的使用技巧,需要的朋友可以參考下2015-04-04
JavaScript創(chuàng)建防篡改對(duì)象的方法分析
這篇文章主要介紹了JavaScript創(chuàng)建防篡改對(duì)象的方法,結(jié)合具體實(shí)例形式分析了javascript基于不可擴(kuò)展對(duì)象、密封的對(duì)象和凍結(jié)的對(duì)象實(shí)現(xiàn)防篡改對(duì)象的相關(guān)操作技巧,需要的朋友可以參考下2018-12-12
JS組件封裝之監(jiān)聽localStorage的變化
這篇文章主要介紹了JS組件封裝之監(jiān)聽localStorage的變化,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09
JavaScript在Android的WebView中parseInt函數(shù)轉(zhuǎn)換不正確問題解決方法
這篇文章主要介紹了JavaScript在Android的WebView中parseInt函數(shù)轉(zhuǎn)換不正確問題解決方法,因轉(zhuǎn)換的字符串?dāng)?shù)字都以0開頭,導(dǎo)致parseInt函數(shù)在瀏覽器和Android WebView中轉(zhuǎn)換結(jié)果不一樣,本文給出了解決方法,需要的朋友可以參考下2015-04-04
JS實(shí)現(xiàn)很酷的EMAIL地址添加功能實(shí)例
這篇文章主要介紹了JS實(shí)現(xiàn)很酷的EMAIL地址添加功能,實(shí)例分析了javascript操作text文本的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-02-02

