uniapp幾行代碼解決滾動(dòng)穿透問(wèn)題(項(xiàng)目實(shí)戰(zhàn))
具體的解決方式:
<template >
<view class="" >
<page-meta :page-style="spanStyle"></page-meta>
</view>
</template>
<script >
export default {
data() {
return {
spanStyle:"overflow:auto"
}
},
methods: {
mask(data){
//當(dāng)蒙層彈起時(shí),固定界面禁止?jié)L動(dòng),當(dāng)蒙層關(guān)閉時(shí),允許滾動(dòng)
if(data){
this.spanStyle="overflow:hidden";
}else{
this.spanStyle="overflow:auto";
}
}
}
}
</script >項(xiàng)目實(shí)戰(zhàn):
<template>
<page-meta :page-style="'overflow:'+(searchPopupVisible?'hidden':'visible')" />
<!--區(qū)域選擇-->
<div class="d-toolbox cf">
<a href="javascript:;" rel="external nofollow" rel="external nofollow" @click="showPopup" class="a-area" :hover="selectText!='區(qū)域'" :isOne="isOne">{{selectText}}</a>
<u-popup :show="searchPopupVisible" mode="bottom" @close="searchPopupVisible = false" class="d-searchPopup cf">
<div class="d-searchPopupBox cf">
<strong>選擇區(qū)域</strong>
<div v-if="resultData.length > 0">
<!--解決滾動(dòng)穿透-->
<scroll-view scroll-y="true" style="height:100%;">
<em v-for="(item,index) in resultData" :key="index" :class="item.region_id == region_id ? 'hover' : ''" @click="selectArea(item)">{{item.region_name}}</em>
</scroll-view>
</div>
<div v-else>
<em>暫無(wú)數(shù)據(jù)</em>
</div>
<a href="javascript:;" rel="external nofollow" rel="external nofollow" @click="searchPopupVisible = false">取消</a>
</div>
</u-popup>
</div>
</template>
<script>
export default {
props: {
region_id: {
type: [String,Number],
default: ''
},
calbackFunName: {
type: String,
default: 'onToolAreaCallback'
},
},
data() {
return {
isOne : false, //是否只有一個(gè)區(qū)域
selectText : '區(qū)域',
searchPopupVisible : false,
resultData : [],
}
},
watch:{
region_id(val){
this.selectText = val == '' ? '區(qū)域' : this.resultData.find(item=>item.region_id == val).region_name
},
},
mounted() {
this.storage_authorInfo = uni.getStorageSync('storage_authorInfo') ? JSON.parse(uni.getStorageSync('storage_authorInfo')) : {};
this.resultData = this.storage_authorInfo.Store;
this.resultData.unshift({'region_name':'全部','region_id':''});
//只有一個(gè)區(qū)域的特殊情況
if(this.resultData.length === 2){
this.isOne = true
this.selectText = this.resultData[1].region_name
}
},
methods: {
showPopup(){
if(this.isOne) return
this.searchPopupVisible = true
},
selectArea(item){
this.searchPopupVisible = false;
this.selectText = item.region_id ? item.region_name : '區(qū)域';
uni.$emit(this.calbackFunName , {
region_id : item.region_id,
region_name : item.region_name
})
}
}
}
</script>
<style lang="scss" scoped>
.d-toolbox {
display:inline-block;
position: relative;
.a-area{
font-size: 24rpx; color:#333; display: flex; align-items: center;
&:after{
content:'';width:24rpx; height:24rpx; background: url(/static/img/index/arrows.png) no-repeat; background-size:100%; margin-left:10rpx;
}
&[isOne="true"]:after{
display:none;
}
&[hover="true"]{
color:#4568E8;
&:after{
background-image: url(/static/img/index/arrows-hover.png);
}
}
}
}
.d-searchPopup{
/deep/.u-popup__content{
border-radius: 20rpx 20rpx 0 0; overflow: hidden;
}
.d-searchPopupBox{
background: #fff;
strong{
display: block;
text-align: center;
font-size:32rpx;
color:#333;
height:100rpx;
line-height: 100rpx;
border-bottom: solid #F5F5F5 1px;
}
div{
position: relative; max-height: 480rpx; overflow-y: auto;
em , a{
display: block;
text-align: center;
color:#333; font-size:28rpx;
height:79rpx; line-height: 79rpx;
border-bottom:solid #F5F5F5 1rpx;
&:last-child{
border:0;
}
}
.hover{
color:#4568E8;
}
}
a{
display: block;
text-align: center;
color:#333; font-size:28rpx;
height:80rpx; line-height: 80rpx;
border-top:solid #F5F5F5 14rpx;
}
}
}
</style>PS:uniapp解決滾動(dòng)條問(wèn)題
在App.vue的style中寫上
/* 解決小程序和app滾動(dòng)條的問(wèn)題 */
/* #ifdef MP-NEIXIN 11 APP-PLUS */
::-webkit-scrollbar {
display: none;
width: 0 !important;
height: 0 !important;
-webkit-appearance: none;
background: transparent;
color: transparent;
}
/* #endif */
/* 解決H5的問(wèn)題 */
/* #ifdef H5 */
uni-scroll-view .uni-scroll-view::webkit-scrollbar {
/* 隱藏滾動(dòng)條,但依舊具備可以滾動(dòng)的功能 */
display: none;
width: 0 !important;
height: 0 !important;
-webkit-appearance: none;
background: transparent;
color: transparent;
}到此這篇關(guān)于uniapp幾行代碼解決滾動(dòng)穿透問(wèn)題的文章就介紹到這了,更多相關(guān)uniapp滾動(dòng)穿透內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳述JavaScript實(shí)現(xiàn)繼承的幾種方式(推薦)
這篇文章主要介紹了詳述JavaScript實(shí)現(xiàn)繼承的幾種方式(推薦)的相關(guān)資料,需要的朋友可以參考下2016-03-03
js中判斷對(duì)象是否為空的三種實(shí)現(xiàn)方法
本篇文章主要是對(duì)js中判斷對(duì)象是否為空的三種實(shí)現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2013-12-12
Cropper.js進(jìn)階之裁剪后保存至本地實(shí)現(xiàn)示例
這篇文章主要為大家介紹了Cropper.js進(jìn)階之裁剪后保存至本地實(shí)現(xiàn)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05
JS組件系列之Bootstrap Icon圖標(biāo)選擇組件
這篇文章給大家介紹js組件系列之Bootstrap Icon圖標(biāo)選擇組件,對(duì)bootstrap icon圖標(biāo)相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧2016-01-01
DWR3 訪問(wèn)WEB元素的兩種方法實(shí)例詳解
這篇文章主要介紹了DWR3 訪問(wèn)WEB元素的兩種方法實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-01-01

