Skip to content
本页导读

Overlay 遮罩层

组件类型:UxOverlayComponentPublicInstance

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

平台兼容性

AndroidiOSweb鸿蒙 Next小程序
xx

Props

属性名类型默认值说明
showBooleanfasle显隐状态
maskCloseBooleantrue点击遮罩是否关闭
opacityNumber0.5遮罩透明度 0-1
fixedOpacityBooleantrue固定透明度
zIndexNumber10001层级z-index

Events

事件名说明参数
close点击遮罩关闭时触发-

示例代码

html
<template>
	<ux-page>
		<ux-navbar :title="title" :border="false"></ux-navbar>
		
		<ux-scroll>
			<ux-card direction="column" icon="flag" title="遮罩层" :bold="true">
				<ux-text text="支持透明度、遮罩点击关闭"></ux-text>
				<ux-row :flex="true" align="top" :mt="5" style="width: 100%;">
					<ux-text text="详细文档:"></ux-text>
					<ux-text style="flex: 1" name="遮罩层" text="https://www.uxframe.cn/component/layout/overlay.html" mode="link"></ux-text>
				</ux-row>
			</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"></ux-text>
			</view>
		</ux-overlay>
	</ux-page>
</template>
<template>
	<ux-page>
		<ux-navbar :title="title" :border="false"></ux-navbar>
		
		<ux-scroll>
			<ux-card direction="column" icon="flag" title="遮罩层" :bold="true">
				<ux-text text="支持透明度、遮罩点击关闭"></ux-text>
				<ux-row :flex="true" align="top" :mt="5" style="width: 100%;">
					<ux-text text="详细文档:"></ux-text>
					<ux-text style="flex: 1" name="遮罩层" text="https://www.uxframe.cn/component/layout/overlay.html" mode="link"></ux-text>
				</ux-row>
			</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"></ux-text>
			</view>
		</ux-overlay>
	</ux-page>
</template>
ts
<script setup>
	let title = ''
	const show = ref(false)
	const opacity = ref(0.5)
	const maskClose = ref(true)
	
	onLoad((e: OnLoadOptions) => {
		title = 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>
	let title = ''
	const show = ref(false)
	const opacity = ref(0.5)
	const maskClose = ref(true)
	
	onLoad((e: OnLoadOptions) => {
		title = 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;
	}
</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;
	}
</style>