小程序自定义弹出层禁止页面滚动

catchtouchmove 在小程序模拟器中没有效果,真机测试时可以

使用catchtouchmove=“true”,会一直弹出警告错误“does not have a method “true” to handle event “touchmove”,所以这里定义个方法

<block wx:if="{{showVideo == true}}">
  <view class="showVideoBg" catchtouchmove="filterViewMove">
        <view>
        <video 
          id="myVideo" 
          src="video_url" 
          binderror="videoErrorCallback" 
          show-center-play-btn='true' 
          show-play-btn="true" 
          autoplay="true"
          object-fit="cover"
          controls
          enable-play-gesture="{{true}}"
          bindended="closeVideo"
        ></video>
        <image src="/images/close.png" class="close_video" bindtap="closeVideo"></image>
      </view>
  </view>
</block>

.showVideoBg{
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100vh;
  background: black;
}
.showVideoBg view{
  width: 100%;
  height: 100%;
  position: relative;
}
.showVideoBg scroll-view{
  width: 100%;
  height: 100%;
}
.showVideoBg video{
  width: 100%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%,-50%);
}
.close_video{
  position: absolute;
  top: 100rpx;
  right: 30rpx;
  width: 60rpx;
  height: 60rpx !important;
}

js

// 定义页面禁止滚动
  filterViewMove: function(){
    return;
  },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以使用uniapp的组件和样式来自定义弹出。以下是一种常见的实现方式: 1. 创建一个新的组件,例如"popup"组件。 2. 在该组件的模板中,可以使用`<slot></slot>`标签来放置弹出的内容。 3. 在组件的样式中,设置弹出的样式,例如位置、背景色、边框等。 4. 在"popup"组件的脚本中,定义控制弹出显示和隐藏的数据和方法。你可以使用`show`变量来控制弹出的显示状态。 5. 在需要弹出页面中,引入"popup"组件,并根据需求设置弹出的内容。 下面是一个简单的示例代码: 在"popup"组件的模板中(popup.vue): ```html <template> <div class="popup" :class="{ active: show }"> <div class="popup-content"> <slot></slot> </div> </div> </template> ``` 在"popup"组件的样式中(popup.vue): ```css <style scoped> .popup { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); display: flex; justify-content: center; align-items: center; z-index: 9999; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; } .popup.active { opacity: 1; pointer-events: auto; } .popup-content { background-color: #fff; padding: 20px; border-radius: 5px; } </style> ``` 在"popup"组件的脚本中(popup.vue): ```javascript <script> export default { data() { return { show: false }; }, methods: { togglePopup() { this.show = !this.show; } } }; </script> ``` 在需要弹出页面中,使用"popup"组件(index.vue): ```html <template> <div> <button @click="togglePopup">打开弹出</button> <popup> <!-- 弹出的内容 --> <h2>自定义弹出</h2> <p>这是弹出的内容。</p> </popup> </div> </template> <script> import Popup from '@/components/popup.vue'; export default { components: { Popup } }; </script> ``` 以上代码示例中,点击按钮将触发`togglePopup`方法,从而切换弹出的显示和隐藏。你可以根据实际需求进行修改和扩展,比如添加动画效果、传递参数等。希望对你有所帮助!

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值