uni-app新建透明页面实现全局弹窗

需求背景

实现一个能遮住原生 tabbarnavbar 的全局操作框

原理

使用一个透明的页面来模拟弹窗,这个页面可以遮住原生 tabbarnavbar

页面配置

{
    "path" : "pages/shootAtWill/shootAtWill",
    "style" : 
    {
        "navigationBarTitleText" : "随手拍",
        "navigationStyle": "custom",
        "backgroundColor": "transparent",
        "app-plus": {
            "animationType": "slide-in-bottom", // 我这边需求是从底部弹出
            "background": "transparent",
            "popGesture": "none",
            "bounce": "none",
            "titleNView": false,
            "animationDuration": 150
        }
    }
}

页面样式

<style>
	page {
		/* 必须的样式,这是页面背景色为透明色 */
		background: transparent; 
	}
</style>
<style lang="scss" scoped>
  // 写你页面的其他样式
</style>

这样的话就新建成功了一个透明的页面,那么这个页面上的东西都可以遮挡住原生 tabbarnavbar

我还加了遮罩:

<template>
  <view>
    <view class="modal" style="z-index: -1"></view>  
    
  </view>
</template>

<style lang="scss" scoped>
   .modal {
      position: fixed;
      top: 0;
      bottom: 0;
      left: 0;
      right: 0;
      background-color: rgba(0, 0, 0, 0.5);
	}
</style>

效果演示

在这里插入图片描述

  • 9
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
好的,关于你的问题,我来尝试回答一下。 在uni-app中,我们可以通过自定义指令来实现全局图片dpr适配。具体步骤如下: 1. 在项目的根目录下,创建一个`/common/directives`目录。 2. 在该目录下,新建一个`index.js`文件,用于存放自定义指令。 3. 在`index.js`文件中,定义一个`img`指令,用于处理所有`<img>`标签。 4. 在`img`指令中,通过`uni.getSystemInfoSync()`方法获取设备的dpr值。 5. 根据dpr值,设置`<img>`标签的`src`属性,以实现图片dpr适配。 下面是示例代码: ```javascript // /common/directives/index.js export default { img: { // 指令定义函数 bind: function(el, binding) { // 获取设备的dpr值 const dpr = uni.getSystemInfoSync().pixelRatio; // 根据dpr值,设置图片的src属性 const imgPath = binding.value; el.setAttribute('src', imgPath + '@' + dpr + 'x'); } } } ``` 使用自定义指令时,需要在`main.js`文件中全局注册自定义指令: ```javascript // /main.js import directives from './common/directives'; // 注册自定义指令 Object.keys(directives).forEach(key => { Vue.directive(key, directives[key]); }); ``` 完成上述步骤后,即可在项目中使用`v-img`指令实现全局图片dpr适配: ```html <template> <img v-img="'/static/img/test.png'" /> </template> ``` 这样,`<img>`标签的`src`属性就会根据设备的dpr值自动添加相应的后缀,以达到图片dpr适配的效果。 希望我的回答能够帮到你,如有疑问请随时提出。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

鹏北海-RemHusband

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值