uniapp自定义蒙层弹窗列表 滑动 底层div也会滑动 取消底层滑动

采用**@touchmove.stop.prevent=“moveHandle”** 阻止父级 页面 滚动条
另弹窗中需要配合 scroll-view scroll-y=“true” class=“scroll-view” 方可滚动 注意添加 “scroll-y=“true””

<view class="popmeng" @tap.stop="stopPop" id="bt" :class="show?'popmeng1':''" >
			<view class="addpop" @tap.stop="" id="addpop" :class="show?'showpop':''" @touchmove.stop.prevent="moveHandle">
				<!-- 拖拽 -->
				<view class="btnpop-box" @touchend='touchend' @touchmove="touchmove($event)"
					@touchstart="touchstart($event)">
					<view class="drag">
					</view>
				</view>
				<view class="pop-tit">
				{{showType==1?'全部藏品':'正在寄售'}}
					<view class="pop-tit-line" >
					</view>
				</view>
				<view class="pop-content">
					<template v-if="lists.length>0">
					<scroll-view scroll-y="true" class="scroll-view">
						<view class="pop-list" v-for="(item,index) in lists" :key="index" @click.stop="goDetail(item.id)">
							<view class="poplist-left">
								<img :src="item.image" alt="">
							</view>
							<view class="poplist-right">
								<view class="pop-list-content">
									<view class="pop-list-tit">
										{{item.name}}
									</view>
									<view class="pop-list-nums-box">
										<view class="pop-list-num" v-if="item.goods_number_new">
											#{{item.goods_number_new}}
										</view>
										<view class="pop-list-nums" v-if="showType == 2">
											{{item.price}}元
										</view>
									</view>
									
								</view>
								<view class="pop-radio" @tap.stop="shangjia(item.id,item.name,1)" v-if="showType == 1">
									<img src="../../assets/shangjia.png" alt="">
								</view>
								<view class="pop-radio" @tap.stop="shangjia(item.id,item.name,2)" v-if="showType == 2">
									<img src="../../assets/xiajia.png" alt="">
								</view>
								<view class="pop-radio" @tap.stop="shangjia(item.id,item.name,3)" v-if="showType == 2" style="margin-left: 48rpx;">
									<img src="../../assets/gaijia.png" alt="">
								</view>
							</view>
						</view>
					</scroll-view>
						
					</template>
				</view>
				<view class="pop-btn-box" style="z-index: 50;">
					<!--  -->
					<view class="pop-btn-submit1" @tap="allshangjia(lists[0].name,4)" v-if="showType==1">
						全部上架
					</view>
					<view class="pop-btn-submit1" @tap.stop="allxiajia()" v-else>
						全部下架
					</view>
				</view>
			</view>
		</view>
<script setup>
	export default {
		data() {
			return {
			show:false;
			}
		},
		methods: {
			// 打开弹窗
			add() {
					this.show = true //打开弹窗
			},
			// 关闭弹窗index
			stopPop() {
				this.$nextTick(() => this.show = false);
			},
			//
			moveHandle(){
				return false;
			},
		}
	}
</script>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果您在 Vue 中使用 `overflow-y` 属性来实现滚动,并且滚动到边界时出现了弹窗底部滑动的问题,可能的原因是滑动时触发了浏览器的默认行为,导致整个页面的滚动。为了避免这种情况,您可以尝试在滑动事件中调用 `event.preventDefault()` 方法来阻止默认行为的发生。 以下是一个使用 Vue 实现的示例代码,您可以参考一下: ```html <template> <div class="container" ref="container" @scroll="handleScroll"> <div class="content"> <!-- 此处为滚动内容 --> </div> <div class="popup" ref="popup"> <!-- 此处为弹窗内容 --> </div> </div> </template> <script> export default { methods: { handleScroll(event) { const container = this.$refs.container; const popup = this.$refs.popup; const scrollTop = container.scrollTop; const containerHeight = container.offsetHeight; const popupHeight = popup.offsetHeight; const popupTop = popup.offsetTop; const popupBottom = popupTop + popupHeight; // 判断弹窗是否在可视区域内 if (popupBottom > scrollTop && popupTop < scrollTop + containerHeight) { // 如果弹窗底部超出可视区域,则将容器滚动到弹窗底部 if (popupBottom > scrollTop + containerHeight) { container.scrollTop = popupBottom - containerHeight; } // 如果弹窗顶部超出可视区域,则将容器滚动到弹窗顶部 if (popupTop < scrollTop) { container.scrollTop = popupTop; } // 阻止默认行为 event.preventDefault(); } } } }; </script> <style> .container { height: 200px; overflow-y: scroll; } .popup { position: absolute; bottom: 0; left: 0; width: 100%; height: 100px; background-color: #fff; } </style> ``` 在上述代码中,我们在 `handleScroll` 方法中判断弹窗是否在可视区域内,并根据其位置调整容器的滚动位置。同时,如果弹窗在可视区域内,我们还调用 `event.preventDefault()` 方法来阻止默认行为的发生,以避免整个页面的滚动。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值