Skip to content
本页导读

Overlay

组件类型:UxOverlayComponentPublicInstance

支持透明度、遮罩点击关闭

平台兼容性

UniApp X

AndroidiOSweb鸿蒙 Next小程序
x

UniApp Vue Nvue

AndroidiOSweb鸿蒙 Next小程序
xxxx

Props

属性名类型默认值说明
showBooleanfasle显隐状态
showBlurBooleanfalse开启模糊背景
blurRadiusNumber10模糊半径
blurColorStringrgba(10,10,10,0.3)模糊颜色
maskCloseBooleantrue点击遮罩是否关闭
opacityNumber$ux.Conf.maskAlpha遮罩透明度0-1
fixedOpacityBooleantrue固定透明度
zIndexNumber10001层级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>