Overlay
组件类型:UxOverlayComponentPublicInstance
支持透明度、遮罩点击关闭
平台兼容性
UniApp X
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
√ | √ | √ | x | √ |
UniApp Vue Nvue
Android | iOS | web | 鸿蒙 Next | 小程序 |
---|---|---|---|---|
x | x | √ | x | x |
Props
属性名 | 类型 | 默认值 | 说明 |
---|---|---|---|
show | Boolean | fasle | 显隐状态 |
showBlur | Boolean | false | 开启模糊背景 |
blurRadius | Number | 10 | 模糊半径 |
blurColor | String | rgba(10,10,10,0.3) | 模糊颜色 |
maskClose | Boolean | true | 点击遮罩是否关闭 |
opacity | Number | $ux.Conf.maskAlpha | 遮罩透明度0-1 |
fixedOpacity | Boolean | true | 固定透明度 |
zIndex | Number | 10001 | 层级z-index |
Events
事件名 | 说明 | 参数 |
---|---|---|
close | 点击遮罩关闭时触发 |
示例代码
html
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :border="false">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll>
<ux-card direction="column" icon="flag-filled" title="遮罩层" :bold="true">
<ux-text text="支持毛玻璃效果、支持透明度、遮罩点击关闭"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="控制" :bold="true">
<ux-col>
<ux-button :margin="[20]" theme="success" text="正常" @click="click(0.5, true)"></ux-button>
<ux-button :margin="[20]" theme="success" text="透明" @click="click(0, true)"></ux-button>
<ux-button :margin="[20]" theme="success" text="不透明" @click="click(1, true)"></ux-button>
<ux-button :margin="[20]" theme="success" text="点击遮罩不可关闭" @click="click(0.5, false)"></ux-button>
</ux-col>
</ux-card>
</ux-scroll>
<ux-overlay :show="show" :opacity="opacity" :mask-close="maskClose" @close="show = false">
<view v-if="show" class="bg">
<ux-text text="Hello UniappX" color="white"></ux-text>
</view>
</ux-overlay>
</ux-page>
</template>
<template>
<ux-page :stack="showDoc">
<ux-navbar :title="title" :border="false">
<template v-slot:right>
<!-- #ifndef MP -->
<ux-button theme="text" icon="/static/tip.png" :icon-size="22" @click="onDoc()"></ux-button>
<!-- #endif -->
</template>
</ux-navbar>
<ux-scroll>
<ux-card direction="column" icon="flag-filled" title="遮罩层" :bold="true">
<ux-text text="支持毛玻璃效果、支持透明度、遮罩点击关闭"></ux-text>
</ux-card>
<ux-card direction="column" icon="arrowright" title="控制" :bold="true">
<ux-col>
<ux-button :margin="[20]" theme="success" text="正常" @click="click(0.5, true)"></ux-button>
<ux-button :margin="[20]" theme="success" text="透明" @click="click(0, true)"></ux-button>
<ux-button :margin="[20]" theme="success" text="不透明" @click="click(1, true)"></ux-button>
<ux-button :margin="[20]" theme="success" text="点击遮罩不可关闭" @click="click(0.5, false)"></ux-button>
</ux-col>
</ux-card>
</ux-scroll>
<ux-overlay :show="show" :opacity="opacity" :mask-close="maskClose" @close="show = false">
<view v-if="show" class="bg">
<ux-text text="Hello UniappX" color="white"></ux-text>
</view>
</ux-overlay>
</ux-page>
</template>
ts
<script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const show = ref(false)
const opacity = ref(0.5)
const maskClose = ref(true)
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/overlay.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e: OnLoadOptions) => {
title.value = e['title'] ?? ''
})
function click(_opacity: number, _maskClose: boolean) {
opacity.value = _opacity
maskClose.value = _maskClose
show.value = true
if(!maskClose.value) {
setTimeout(() => {
show.value = false
}, 3000)
}
}
</script>
<script setup>
import * as plus from '@/uni_modules/ux-plus'
const title = ref('')
const show = ref(false)
const opacity = ref(0.5)
const maskClose = ref(true)
const showDoc = ref(false)
function onDoc() {
plus.openWeb({
title: '在线文档',
url: 'https://www.uxframe.cn/component/overlay.html',
// blur: 1,
success: () => {
showDoc.value = true
},
complete: () => {
showDoc.value = false
}
})
}
onLoad((e: OnLoadOptions) => {
title.value = e['title'] ?? ''
})
function click(_opacity: number, _maskClose: boolean) {
opacity.value = _opacity
maskClose.value = _maskClose
show.value = true
if(!maskClose.value) {
setTimeout(() => {
show.value = false
}, 3000)
}
}
</script>
css
<style lang="scss">
.bg {
position: fixed;
top: 20%;
left: 20%;
right: 20%;
bottom: 20%;
display: flex;
align-items: center;
justify-content: center;
background-color: darkblue;
z-index: 1000000;
}
</style>
<style lang="scss">
.bg {
position: fixed;
top: 20%;
left: 20%;
right: 20%;
bottom: 20%;
display: flex;
align-items: center;
justify-content: center;
background-color: darkblue;
z-index: 1000000;
}
</style>