当前位置: 首页 > news >正文

uniapp 弹窗封装(上、下、左、右、中五个方位)

无脑复制即可!!!

<template><view><viewv-if="mask"class="tui-drawer-mask":class="{ 'tui-drawer-mask_show': visible }":style="{ zIndex: maskZIndex }"@tap="handleMaskClick"@touchmove.stop.prevent="moveHandle"></view><viewclass="tui-drawer-container":class="[`tui-drawer-container_${mode}`, visible ? `tui-drawer-${mode}__show` : '']":style="{ zIndex: zIndex, backgroundColor: backgroundColor }"@touchmove.stop.prevent="moveHandle"><slot></slot></view></view>
</template><script>
/*** 超过一屏时插槽使用scroll-view**/
export default {name: 'customDrawer',emits: ['close'],props: {visible: {type: Boolean,default: false},mask: {type: Boolean,default: true},maskClosable: {type: Boolean,default: true},// center left right bottom topmode: {type: String,default: 'center'},//drawer z-indexzIndex: {type: [Number, String],default: 990},//mask z-indexmaskZIndex: {type: [Number, String],default: 980},backgroundColor: {type: String,default: '#fff'}},methods: {moveHandle() {return false;},handleMaskClick() {if (!this.maskClosable) {return;}this.$emit('close', {});}}
};
</script><style scoped>
.tui-drawer-mask {opacity: 0;visibility: hidden;position: fixed;top: 0;left: 0;right: 0;bottom: 0;background-color: rgba(0, 0, 0, 0.6);transition: all 0.3s ease-in-out;
}
.tui-drawer-mask_show {display: block;visibility: visible;opacity: 1;
}.tui-drawer-container {position: fixed;height: 100.2%;transform-origin: center;transition: all 0.3s ease-in-out;opacity: 0;overflow-y: scroll;-webkit-overflow-scrolling: touch;-ms-touch-action: pan-y cross-slide-y;-ms-scroll-chaining: none;-ms-scroll-limit: 0 50 0 50;
}.tui-drawer-container_center {top: 50%;left: 50%;height: auto;transform: translate3d(-50%, -50%, 0) scale(0);
}.tui-drawer-container_left {left: 0;top: 50%;transform: translate3d(-100%, -50%, 0);
}.tui-drawer-container_right {right: 0;top: 50%;transform: translate3d(100%, -50%, 0);
}.tui-drawer-container_bottom,
.tui-drawer-container_top {width: 100%;height: auto !important;min-height: 20rpx;transform-origin: center;transition: all 0.3s ease-in-out;
}.tui-drawer-container_bottom {bottom: 0;left: 0;transform: translate3d(0, 100%, 0);
}.tui-drawer-container_top {top: 0;left: 0;transform: translate3d(0, -100%, 0);
}.tui-drawer-center__show {opacity: 1;transform: translate3d(-50%, -50%, 0) scale(1);
}.tui-drawer-left__show,
.tui-drawer-right__show {opacity: 1;transform: translate3d(0, -50%, 0);
}
.tui-drawer-top__show,
.tui-drawer-bottom__show {opacity: 1;transform: translate3d(0, 0, 0);
}
</style>

页面中使用

<template><custom-drawer mode="" :zIndex="" :maskZIndex="" :visible="" backgroundColor="" :mask="" @close=""><view>你的插槽内容</view></custom-drawer>
</template><script>
import customDrawer from '封装的组件路径.vue';export default {components: {customDrawer}
}
</script>

相关文章:

  • 【FFmpeg+SDL】使用FFmpeg捕获屏幕,SDL显示
  • win10下安装redis并设置开机自启动
  • 前端的面试笔记——JavaScript篇(二)
  • 口播视频怎么剪!利用AI提高口播视频剪辑效率并增强”网感”
  • MATLAB安装全攻略:常见问题与解决方案
  • Linux | Linux系统安装虚拟机教程(超级简单)
  • 以项目的方式学QT开发(一)——超详细讲解(120000多字详细讲解,涵盖qt大量知识)逐步更新!
  • 比亚迪跨界降维打击!将正式宣布跨界,进入两三轮电动车电池市场
  • 解决xxx.jar中没有主清单属性的问题
  • ubuntu18 设置静态ip
  • Milvus Docker 部署教程
  • 内网互通原则详解!
  • 设计并应用一个IIR-ButterWorth-Filter的例子
  • LLM笔记(三)位置编码(1)
  • 【Matlab】最新版2025a发布,深色模式、Copilot编程助手上线!
  • list简单模拟实现
  • AI时代的弯道超车之第十四章:AI与生活和生命的改变
  • 山火中的动态坐标:北斗头盔B3为逆行者铺就生命通道
  • CSRF 和 XSS 攻击分析与防范
  • 02、基础入门-Spring生态圈
  • 美国关税压力下,日本经济一年来首次萎缩
  • 王伟妻子人民日报撰文:81192,一架永不停航的战机
  • 李强:把做强国内大循环作为推动经济行稳致远的战略之举
  • 伊朗最高领袖顾问:伊朗愿承诺永不制造核武,换取美解除制裁
  • 为何选择上海?两家外企提到营商环境、人才资源……
  • 法学联合书单|法庭上的妇女