简单易修改的弹框组件

使用场景

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

弹窗组件

适用框架 vue, uniapp
使用再uniapp 框架中可简单修改标签尺寸单位后使用
pxrpx

<!-- vue -->
<template>
	<div v-show="ishide" @touchmove.stop.prevent>
		<!-- 遮罩 -->
		<div class="mask" :style="maskStyle"></div>
		<!-- 内容 -->
		<div class="tip" :style="tipStyle">
			<slot></slot>
		</div>
	</div>
</template>
<!-- uniapp -->
<!-- 
<template>
	 <view v-show="ishide" @touchmove.stop.prevent>
	 	<view class="mask" :style="maskStyle"></view>
	 	<view class="tip" :style="tipStyle">
	 		<slot></slot>
	 	</view>
	 </view>
</template>
 -->

<script>
	export default {
		props: {
			// 控制弹窗显隐
			ishide: {
				type: Boolean,
				required: true
			},
			// 设置弹窗层级
			zindex: {
				type: Number,
				default: 99
			},
			// 设置遮罩透明度
			opacity: {
				type: Number,
				default: 0.6
			},
			// 设置内容区宽度
			width: {
				type: String,
				default: '70%'
			},
			// 设置内容区高度
			height: {
				type: String,
				default: '300px'
			},
			// 设置内容区圆角
			radius: {
				type: String,
				default: '10px'
			},
			// 设置内容区底色
			bgcolor: {
				type: String,
				default: '#FFFFFF'
			}
		},
		computed: {
			// 遮罩样式
			maskStyle() {
				return `
					z-index:${this.zindex};
					background:rgba(0,0,0,${this.opacity});
				`
			},
			// 内容样式
			tipStyle() {
				return `
					width:${this.width};
					height:${this.height};
					z-index:${this.zindex+1};
					border-radius:${this.radius};
					background-color:${this.bgcolor};
				`
			}
		}
	}
</script>

<style scoped>
	.mask {
		position: fixed;
		bottom: 0;
		right: 0;
		left: 0;
		top: 0;
	}

	.tip {
		position: fixed;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
	}
</style>

组件使用

<template>
	<div>
		<!-- 开关控制 -->
		<button type="default" @click="isshow=!isshow">弹窗</button>
		<!-- 使用组件 -->
		<zwy-popup :ishide='isshow' width="70%" height="700rpx" radius="40rpx">
			<!-- 自定义展示内容 -->
			<div class="content">
				<div class="image"></div>
				<div class="title">活动标题</div>
				<div>内容</div>
				<div>内容</div>
				<div class="info">内容</div>
				<div class="btn">按钮</div>
			</div>
			<!-- 自定义关闭按钮 -->
			<div class="close" @click="isshow=false"></div>
		</zwy-popup>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				isshow: false
			}
		}
	}
</script>

<style scoped>
	.content {
		width: 100%;
		height: 100%;
		display: flex;
		align-items: center;
		flex-direction: column;
		justify-content: center;
		background-color: coral;
		border-radius: 10px;
	}

	.image {
		width: 80px;
		height: 80px;
		border-radius: 50%;
		background: #4CD964;
	}

	.title {
		font-size: 18px;
		margin: 30px 0 20px 0;
	}

	.info {
		margin: 20px 0;
		font-size: 12px;
		text-align: center;
		background: #F5F5F5;
		border-radius: 8px;
		padding: 8px 10px;
	}

	.btn {
		width: 100px;
		height: 30px;
		font-size: 12px;
		line-height: 30px;
		text-align: center;
		border-radius: 16px;
		background: linear-gradient(-90deg, #FEEF43, #E9D81B);
	}

	.close {
		width: 30px;
		height: 30px;
		color: #FFFFFF;
		line-height: 30px;
		text-align: center;
		border-radius: 50%;
		border: 1px solid #FFFFFF;
		position: relative;
		bottom: -10%;
		left: 50%;
		transform: translate(-50%, -50%);
	}
</style>

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

织_网

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

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

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

打赏作者

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

抵扣说明:

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

余额充值