uni-app自定义弹窗,底部页面触摸穿透问题解决方案(精华)

时间:2025-03-09 09:50:59
  • <template>
  • <view class="" :class="isUps == true ? 'prevent' : ''">
  • <!-- 原页面内容 -->
  • <view class="content">
  • </view>
  • <!-- 遮罩 -->
  • <view class="isUps" v-if="shade"></view>
  • <!-- 弹窗 -->
  • <view class="ups" v-if="isUps">
  • <!-- 弹窗内容比较多,需要滑动的情况 -->
  • <scroll-view scroll-y="true" >
  • <view class=""></view>
  • </scroll-view>
  • <!-- 或 -->
  • <!-- 内容比较少,不需要滑动弹窗的情况 -->
  • <!-- <view class=""></view> -->
  • </view>
  • </view>
  • </template>
  • <script>
  • export default{
  • data(){
  • return{
  • isUps:false,//控制弹窗与遮罩的显示与隐藏(弹窗与
  • 遮罩是同时显示与隐藏的,所以用同一个变量控制就ok了)
  • }
  • },
  • }
  • </script>
  • <style>
  • /* 起到固定的作用 ,从而解决原页面触摸穿透的问题*/
  • .prevent {
  • width: 100%;
  • height: 100%;
  • position: fixed;
  • top: 0;
  • left: 0;
  • overflow: hidden;
  • }
  • /* 下面样式根据自己情况来更改,只是举例 */
  • /* 原页面内容 */
  • .content{
  • width:100%;
  • height: 2000upx;
  • }
  • /* 遮罩样式 */
  • .shade{
  • width:100%;
  • height: 100%;
  • position: fixed;
  • top:0;
  • left:0;
  • z-index: 98;
  • }
  • /* 弹窗样式 */
  • .ups{
  • width:100%;
  • height: 400upx;
  • position: fixed;
  • left:0;
  • bottom: 0;
  • border:1upx solid green;
  • background-color: #fff;
  • z-index:99;
  • }
  • .ups scroll-view{
  • height: 300upx;
  • }
  • </style>