Skip to content
官方QQ交流群
pc端ui:468705115   点此加入
移动端ui:468217742   点此加入
技术交流1:87208295   点此加入
技术交流2:787747122   点此加入
官网
云控制台
开放平台
关注微信公众号
代码仓库: 码云

Overlay 遮罩层

创建一个遮罩层,用于强调特定的页面元素,并阻止用户对遮罩下层的内容进行操作,一般用于弹窗场景

平台差异说明

App(vue)App(nvue)H5小程序

基本使用

  • 通过show参数配置是否显示遮罩
  • 遮罩被点击时,会发送一个click事件,如不需要此事件,请设置mask-click-able参数为false
html
<template>
	<up-overlay :show="show" @click="show = false"></up-overlay>
</template>

<script>
	export default {
		data() {
			return {
				show: true
			}
		}
	}
</script>

嵌入内容

通过默认插槽可以在遮罩层上嵌入任意内容
注意:如果不想让slot插槽内容的点击事件冒泡到遮罩,请给指定元素添加上@tap.stop

html
<template>
	<up-overlay :show="show" @click="show = false">
		<view class="warp">
			<view class="rect" @tap.stop></view>
		</view>
	</up-overlay>
</template>

<script>
	export default {
		data() {
			return {
				show: true
			}
		}
	}
</script>

<style scoped>
	.warp {
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
	}

	.rect {
		width: 120px;
		height: 120px;
		background-color: #fff;
	}
</style>

遮罩样式

  • 通过duration设置遮罩淡入淡出的时长,单位ms
html
<up-overlay :show="show" :duration="400" :z-index ="999" :opacity="0.3"></up-overlay>

此页面源代码地址

页面源码地址


 github  gitee

API

Props

参数说明类型默认值可选值
show是否显示遮罩Booleanfalsetrue
zIndexz-index 层级String | Number10070-
duration动画时长,单位毫秒String | Number300-
opacity不透明度值,当做rgba的第四个参数String | Number0.5-

Events

事件名说明回调参数
click点击遮罩发送此事件-

Slot

名称说明
default默认插槽,用于在遮罩层上方嵌入内容

Copyright © 2017 10yun.com | 十云提供计算服务-IPV6 | ctocode组开发