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

微信小程序页面容器弹出层

效果图

请添加图片描述

.JS

Page({data: {show: false,duration: 300,position: 'right',round: false,overlay: true,customStyle: '',overlayStyle: ''},popup(e) {const position = e.currentTarget.dataset.positionlet customStyle = ''let duration = this.data.durationswitch(position) {case 'top':case 'bottom': customStyle = 'height: 30%;'breakcase 'right':break}this.setData({position,show: true,customStyle,duration})},changeRound() {this.setData({round: !this.data.round})},changeOverlay() {this.setData({overlay: !this.data.overlay, show: true})},changeOverlayStyle(e) {let overlayStyle = ''const type = e.currentTarget.dataset.typeswitch(type) {case 'black':overlayStyle = 'background-color: rgba(0, 0, 0, 0.7)'breakcase 'white':overlayStyle = 'background-color: rgba(255, 255, 255, 0.7)'breakcase 'blur':overlayStyle = 'background-color: rgba(0, 0, 0, 0.7); filter: blur(4px);'}this.setData({overlayStyle, show: true})},exit() {this.setData({show: false})},
})

.WXML


<view class="title">弹出位置</view>
<view class="box"><button class="btn" bindtap="popup" data-position="right">右侧弹出</button><button class="btn" bindtap="popup" data-position="top">顶部弹出</button><button class="btn" bindtap="popup" data-position="bottom">底部弹出</button><button class="btn" bindtap="popup" data-position="center">中央弹出</button>
</view><view class="title">弹窗圆角</view>
<view class="box"><button class="btn" bindtap="changeRound">设置{{round ? '直角' : '圆角'}}</button>
</view><view class="title">遮罩层</view>
<view class="box"><button class="btn" bindtap="changeOverlay">设置{{overlay ? '无' : '有'}}遮罩</button><button class="btn" bindtap="changeOverlayStyle" data-type="black">黑色半透明遮罩</button><button class="btn" bindtap="changeOverlayStyle" data-type="white">白色半透明遮罩</button><button class="btn" bindtap="changeOverlayStyle" data-type="blur">模糊遮罩</button></view><page-container show="{{show}}"round="{{round}}"overlay="{{overlay}}"duration="{{duration}}"position="{{position}}"close-on-slide-down="{{false}}"bindbeforeenter="onBeforeEnter"bindenter="onEnter"bindafterenter="onAfterEnter"bindbeforeleave="onBeforeLeave"bindleave="onLeave"bindafterleave="onAfterLeave"bindclickoverlay="onClickOverlay"custom-style="{{customStyle}}"overlay-style="{{overlayStyle}}"
><view class="detail-page"><button type="primary" bindtap="exit">推出</button></view>
</page-container>

.WXSS

page {background-color: #f7f8fa;color: #323232;width: 100%;height: 100%;
}.box {margin: 0 12px;
}.title {margin: 0;padding: 32px 16px 16px;color: rgba(69, 90, 100, 0.6);font-weight: normal;font-size: 18px;line-height: 20px;text-align: center;
}.btn {display: block;width: 100%;margin: 10px 0;background-color: #fff;
}.detail-page {width: 100%;height: 100%;min-height: 300px;display: flex;align-items: center;justify-content: center;
}

官方文档

https://developers.weixin.qq.com/miniprogram/dev/component/page-container.html

遇到问题可以看我主页加我Q,很少看博客,对你有帮助别忘记点赞收藏。

http://www.dtcms.com/a/252414.html

相关文章:

  • Next.js面试题:API深度解析
  • LangChain 与 Milvus 的碰撞:全文检索技术实践
  • java 设计模式_行为型_23状态模式
  • 论文笔记:CAN LLMS UNDERSTAND TIME SERIES ANOMALIES?
  • Kafka Connect实战:从环境搭建到全流程操作
  • solana 编写智能合约 然后调用它
  • C#/.NET/.NET Core技术前沿周刊 | 第 42 期(2025年6.9-6.15)
  • Debian 编译安装 ruby3.2
  • webpack到vite的改造之路
  • SOME/IP学习随笔
  • Trae - 非科班在建模比赛中的 AI 编程手|AI编程社知识库精选
  • vscode snippet 工程模板文件分享
  • 【SSH】在VScode中配置SSH
  • 一次硬件恢复之后数据文件0kb的故障恢复---惜分飞
  • 本地生活是如何进行抽佣的
  • 19|Whisper+ChatGPT:请AI代你听播客
  • Flask 快速精通:从入门到实战的轻量级 Web 框架指南
  • git submodule 和git repo介绍
  • 告别微服务,迎接SCS(Self-Contained Systems)?新概念还是炒冷饭?
  • 算法 学习 排序 2025年6月16日10:25:37
  • MySQL 命令行的核心操作命令详解
  • 始理解NLP:我的第一章学习心得
  • SQL注入漏洞-下篇
  • Hive 3.x集成Apache Ranger:打造精细化数据权限管理体系
  • 【Unity笔记】Unity URP 渲染中的灯光数量设置— 场景、使用方法与渲染原理详解
  • Mac Mini M4 安装 jdk8 以及 隐藏 设置内的Java菜单
  • Mac 安装JD-GUI
  • Windows PPT/word怎么pdf不降低分辨率,插入可编辑
  • CSS 选择器、PxCook软件、盒子模型
  • UE5 自动寻路AI Move To节点学习笔记